Interactive CSS 3D Transform

Developer
Size
3,690 Kb
Views
6,072

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 Previews

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);
Interactive CSS 3D Transform - Script Codes
Interactive CSS 3D Transform - Script Codes
Home Page Home
Developer Assaf Gelber
Username agelber
Uploaded January 03, 2023
Rating 4.5
Size 3,690 Kb
Views 6,072
Do you need developer help for Interactive CSS 3D Transform?

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!

Assaf Gelber (agelber) Script Codes
Create amazing marketing copy with AI!

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!