Interactive CSS 3D Transform
How do I make an interactive css 3d transform?
Play around with CSS 3D transforms with your mouse. Drag to rotate and use your mousewheel to scale. . What is a interactive css 3d transform? How do you make a interactive css 3d transform? This script and codes were developed by Assaf Gelber on 03 January 2023, Tuesday.
Interactive CSS 3D Transform - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Interactive CSS 3D Transform</title> <script src="https://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ @import url(https://fonts.googleapis.com/css?family=Rokkitt);
@import url(https://fonts.googleapis.com/css?family=Numans);
body { font-family: Numans;
}
#tips, h1 { color: #444; user-select: none; margin: 5px;
}
#transform { width: 300px; height: 300px; background: #DD312F; border: 5px solid #444; color: #444; margin: 50px auto; cursor: move;
}
#css { font-family: Rokkitt; background: #002A38; border: 1px solid #444; color: #B98D00; padding: 10px;
}
#css:before { content: "transform: "; color: #D33683;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <h1>Interactive CSS 3D Transform</h1>
<div id='tips'> Drag the square around. Also, use your mouse wheel to scale.
</div>
<div id='transform'></div>
<div id='css'> perspective(500px) rotateX(0deg) rotateY(0deg) scale(1)
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Interactive CSS 3D Transform - Script Codes CSS Codes
@import url(https://fonts.googleapis.com/css?family=Rokkitt);
@import url(https://fonts.googleapis.com/css?family=Numans);
body { font-family: Numans;
}
#tips, h1 { color: #444; user-select: none; margin: 5px;
}
#transform { width: 300px; height: 300px; background: #DD312F; border: 5px solid #444; color: #444; margin: 50px auto; cursor: move;
}
#css { font-family: Rokkitt; background: #002A38; border: 1px solid #444; color: #B98D00; padding: 10px;
}
#css:before { content: "transform: "; color: #D33683;
}
Interactive CSS 3D Transform - Script Codes JS Codes
var el = document.getElementById('transform'), css = document.getElementById('css'), width = el.clientWidth, height = el.clientHeight, perspective = 500, rotateX = 0, rotateY = 0, scale = 100, isDown = false, reverse = false, lastX, lastY;
function scaleVal() { var strScale = scale.toString(); if (scale >= 100) { return parseFloat(strScale[0] + '.' + strScale.slice(1)); } return parseFloat('0.' + strScale);
}
function updateTransform() { var pProp = 'perspective(' + perspective + 'px)', xProp = 'rotateX(' + rotateX + 'deg)', yProp = 'rotateY(' + rotateY + 'deg)', sProp = 'scale(' + scaleVal() + ')', props = [pProp, xProp, yProp, sProp].join(' '); el.style[Modernizr.prefixed('transform')] = props; css.innerText = props;
}
function wheel(e) { e.preventDefault(); var delta = e.wheelDelta || -e.detail; scale += delta > 0 ? 5 : -5; updateTransform();
}
el.addEventListener('mousedown', function(e) { isDown = true; lastX = e.clientX; lastY = e.clientY;
}, false);
el.addEventListener('mousewheel', wheel, false);
el.addEventListener('DOMMouseScroll', wheel, false);
document.addEventListener('mousemove', function(e) { if (isDown) { xMultiplier = 180 / height / scaleVal(); yMultiplier = 180 / width / scaleVal(); rotateX += (lastY - e.clientY) * xMultiplier; rotateY += (lastX - e.clientX) * yMultiplier * (reverse ? 1 : -1); rotateX = Math.floor(rotateX % 360); rotateY = Math.floor(rotateY % 360); reverse = Math.abs(Math.floor(rotateX / 90) % 4) > 1; lastX = e.clientX; lastY = e.clientY; updateTransform(); }
}, false);
document.addEventListener('mouseup', function() { isDown = false;
}, false);
Developer | Assaf Gelber |
Username | agelber |
Uploaded | January 03, 2023 |
Rating | 4.5 |
Size | 3,690 Kb |
Views | 6,072 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Skew Demo | 3,209 Kb |
Pure CSS Image Gallery | 3,911 Kb |
Blurring Menu | 2,934 Kb |
Social Link Handle Animation | 3,241 Kb |
Perspective Demo | 3,143 Kb |
Origin Demo | 3,523 Kb |
RotateX and Y Demo | 3,329 Kb |
Scale Demo | 3,214 Kb |
Transition Demo | 2,780 Kb |
Form Placeholder Labels | 3,824 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
A Pen by Sooba | Sooba | 2,516 Kb |
CSS3 Form Page Design | Rssatnam | 3,613 Kb |
Simple DevTools | Deegill | 2,511 Kb |
Image Stack Test SCSS | CalvinMorett | 2,799 Kb |
Learning FlexBox | Alex_rodrigues | 2,821 Kb |
Three js | Paulq | 2,353 Kb |
Portfolio Page | KaylaMT | 1,983 Kb |
CSS Google Now | Jackmoran | 3,196 Kb |
The Rope | Chribbe | 2,886 Kb |
Hexagons | Ashmind | 4,360 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!