JS實(shí)現(xiàn)六邊形3D拖拽翻轉(zhuǎn)效果的方法
更新時(shí)間:2016年09月11日 10:11:37 投稿:daisy
這篇文章給大家分享一個(gè)利用javascript實(shí)現(xiàn)3D六邊形拖拽翻轉(zhuǎn)的效果實(shí)例,實(shí)現(xiàn)后的效果很贊,對(duì)大家的學(xué)習(xí)Javascript具有一定的參考借鑒價(jià)值,有需要的朋友們一起去來(lái)看看吧。
效果圖


實(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>
以上就是這篇文章的全部?jī)?nèi)容,怎么樣?效果很好吧,感興趣的朋友們自己運(yùn)行看看效果,希望這篇文章對(duì)大家能有一定的幫助。
相關(guān)文章
微信小程序 JS動(dòng)態(tài)修改樣式的實(shí)現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于微信小程序JS動(dòng)態(tài)修改樣式的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-12-12
ionic js 復(fù)選框 與普通的 HTML 復(fù)選框到底有沒(méi)區(qū)別
本文通過(guò)實(shí)例給大家演示ionic js 復(fù)選框 與普通的 HTML 復(fù)選框到底有沒(méi)區(qū)別的相關(guān)知識(shí),非常不錯(cuò)具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧2016-06-06
js實(shí)現(xiàn)無(wú)縫滾動(dòng)雙圖切換效果
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)無(wú)縫滾動(dòng)雙圖切換效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07
JavaScript實(shí)現(xiàn)構(gòu)造json數(shù)組的方法分析
這篇文章主要介紹了JavaScript實(shí)現(xiàn)構(gòu)造json數(shù)組的方法,結(jié)合實(shí)例形式對(duì)比分析了javascript構(gòu)造json數(shù)組的實(shí)現(xiàn)方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2018-08-08

