效果圖
實例代碼如下:
<! Doctype HTML公共“ - // W3C // DTD XHTML 1.0 Transitional // en”“” http://www.w.org/tr/xhtml1/dtd/xhtml1/xhtml1-xhtml1-transitional.dtddddd"> <httml xmlns =“ http://www.w3.org/1999/xhtml”> <head> <head> <meta http-equiv =“ content-type” content =“ text/html; charset; charset = utf-8“/> utf-8”/> <tittle> <tittle> javascript> javascript> #box {width:200px;高度:200px; Margin:200px Auto;背景:#ccc;位置:相對;變換:透視圖(800px)rotatey(-60deg)rotatex(45DEG);變換風格:Preserve-3d;} #Box Div {width:width:100%;高度:100%;位置:絕對;頂:0;左:0;背景大小:封面; -webkit-box shadow:0 0 100px#5fbcff;不透明度:0.8;} .front {transform:translatez(100px);背景:#f00;} .back {transform:translatez(-100px);背景:#20ab4f;} .top {transform:translatey(-100px)rotatex(90deg);背景:#ff7800;} .bottom {轉換:translatey(100px)rotatex(-90deg);背景:#00f6ff;} .left {transform:translatex(-100px)rotatey(90deg);背景:#0084ff;} .right {transform:translatex(100px)rotatey(-90deg);背景:#b400ff;} </style> <script> window.onload = function(){var odiv = document.queryselector(“#box”); var y = -60; var x = 45; odiv.onmousedown = function(ev){var ev = ev || event; var disx = ev.clientx-y; var disy = ev.clienty-x; document.onmousemove = function(ev){var ev = ev || event; y = ev.clienty-disy; x = ev.clientx-disx; odiv.style.transform ='perspective(800px)rotatex('+x+'deg)rotatey('+y+'deg)'; } document.onmouseup = function(){document.onmouseup = null; document.onmousemove = null; odiv.releasecapture && odiv.releasecapture(); } odiv.setCapture && odiv.setCapture()返回false; }} </script> </head> <body> <div id =“ box”> <div> </div> <div> </div> </div> <div> </div> </div> <div> </div> </div> <div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </hody> </html> </html> </html>以上就是這篇文章的全部內容,怎麼樣?效果很好吧,感興趣的朋友們自己運行看看效果,希望這篇文章對大家能有一定的幫助。 ,希望這篇文章對大家能有一定的幫助。