JS實(shí)現(xiàn)六邊形3D拖拽翻轉(zhuǎn)效果的方法
效果圖
實(shí)例代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>javascript六邊形3d拖拽翻轉(zhuǎn)效果</title> </head> <style> #box{width:200px;height:200px;margin: 200px auto; background: #ccc; position: relative; transform:perspective(800px) rotateY(-60deg) rotateX(45deg);transform-style:preserve-3d;} #box div{width:100%;height: 100%; position: absolute;top:0;left:0; background-size: cover;-webkit-box-shadow:0 0 100px #5fbcff; opacity: 0.8;} .front{ transform: translateZ(100px); background:#f00;} .back{transform: translateZ(-100px); background:#20ab4f;} .top{transform:translateY(-100px) rotateX(90deg); background: #ff7800;} .bottom{transform:translateY(100px) rotateX(-90deg); background: #00f6ff;} .left{transform:translateX(-100px) rotateY(90deg); background: #0084ff;} .right{transform:translateX(100px) rotateY(-90deg); background: #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() return false; } } </script> </head> <body> <div id="box"> <div class="front"></div> <div class="back"></div> <div class="top"></div> <div class="bottom"></div> <div class="left"></div> <div class="right"></div> </div> </body> </html>
以上就是這篇文章的全部內(nèi)容,怎么樣?效果很好吧,感興趣的朋友們自己運(yùn)行看看效果,希望這篇文章對(duì)大家能有一定的幫助。
相關(guān)文章
js合并兩個(gè)數(shù)組生成合并后的key:value數(shù)組
這篇文章主要是介紹了js將兩個(gè)數(shù)組合并為類json方式,需要的朋友可以參考下2018-05-05JavaScript使用表單元素驗(yàn)證表單的示例代碼
這篇文章主要介紹了JavaScript使用表單元素驗(yàn)證表單的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08Javascript控制input輸入時(shí)間格式的方法
這篇文章主要介紹了Javascript控制input輸入時(shí)間格式的方法,涉及鼠標(biāo)事件及正則表達(dá)式的靈活應(yīng)用,需要的朋友可以參考下2015-01-01js實(shí)現(xiàn)從數(shù)組里隨機(jī)獲取元素
這篇文章主要介紹了js實(shí)現(xiàn)從數(shù)組里隨機(jī)獲取元素的方法,以及個(gè)人封裝的js代碼分享,十分的實(shí)用,這里推薦給小伙伴們2015-01-01微信小程序移動(dòng)拖拽視圖-movable-view實(shí)例詳解
這篇文章主要介紹了微信小程序移動(dòng)拖拽視圖-movable-view的實(shí)例代碼,代碼簡單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08基于JS+HTML實(shí)現(xiàn)彈窗提示是否確認(rèn)提交功能
這篇文章主要介紹了基于JS+HTML實(shí)現(xiàn)彈窗提示是否確認(rèn)提交功能,需要的朋友可以參考下2020-06-06微信小程序webview實(shí)現(xiàn)長按點(diǎn)擊識(shí)別二維碼功能示例
這篇文章主要介紹了微信小程序webview實(shí)現(xiàn)長按點(diǎn)擊識(shí)別二維碼功能,結(jié)合實(shí)例形式分析了webview二維碼識(shí)別相關(guān)操作技巧,需要的朋友可以參考下2019-01-01javascript中for/in循環(huán)及使用技巧
如果您希望一遍又一遍地運(yùn)行相同的代碼,并且每次的值都不同,那么使用循環(huán)是很方便的,本篇文章給大家介紹javascript中for/in循環(huán)及使用技巧 ,需要的朋友可以參考下2015-09-09