JavaScript制作3D旋轉(zhuǎn)相冊

本文實例為大家分享了js 3D旋轉(zhuǎn)相冊展示的具體代碼,供大家參考,具體內(nèi)容如下

創(chuàng)新互聯(lián)堅持網(wǎng)頁設(shè)計,我們不會倒閉、轉(zhuǎn)行,已經(jīng)持續(xù)穩(wěn)定運營十年。專業(yè)網(wǎng)站制作公司技術(shù),豐富的成功經(jīng)驗和創(chuàng)作思維,提供一站式互聯(lián)網(wǎng)解決方案,攜手廣大客戶,共同發(fā)展進步。我們不僅會設(shè)計網(wǎng)站,更會成都全網(wǎng)營銷推廣。幫助中小型企業(yè)在“互聯(lián)網(wǎng)+"的時代里通過推廣營銷傳播路線轉(zhuǎn)型升級,累計幫助多家客戶實現(xiàn)網(wǎng)絡(luò)營銷化,與我們一起攜手共創(chuàng)未來!

源代碼:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Title</title>
 <style>
 *{padding:0;margin:0; font-family: "Proxima Nova","proxima-nova","Helvetica Neue",Helvetica,Arial,sans-serif !important;}
 html body{overflow: hidden;}
 body{background:#ccc;}
 .box{width:140px; height:200px; -webkit-transform-style:preserve-3d; -webkit-transform: perspective(800px) rotateY(0deg) rotateX(0deg); position:relative; margin:400px auto;}
 .box span{width:140px; height:200px; position: absolute; background:deepskyblue; font-size:20px;
  text-align: center; line-height:200px; color:white;}
 </style>
 <script>
 function r2n(n){
  return n*Math.PI/180
 }
 window.onload=function(){
  var oBox=document.getElementsByClassName('box')[0];
  var aS=document.getElementsByTagName('span');
  for(var i=0;i<aS.length;i++){
  aS[i].style.WebkitTransition='1s all ease '+(aS.length-i)*.1+'s';
  aS[i].style.WebkitTransform='rotateY('+i*360/aS.length+'deg)'+' translateZ(500px) '
  }
  var pos=[];
  var x=0;
  var y=0;
  var timer=null;
  var timer2=null;
  document.onmousedown=function(ev){
  timer=setInterval(function(){
   pos[0]=pos[2];
   pos[1]=pos[3];
   pos[2]=x;
   pos[3]=y;
  },30);
  var disx=ev.pageX-x;
  var disy=ev.pageY-y;
  document.onmousemove=function(ev){
   x=ev.pageX-disx;
   y=ev.pageY-disy;
   oBox.style.WebkitTransform=' perspective(800px)'+' rotateY('+x/3+'deg)'+'rotateX('+-y/3+'deg)';
  };
  document.onmouseup=function(){
   clearInterval(timer);
   var speedx=pos[2]-pos[0];
   var speedy=pos[3]-pos[1];
   timer2=setInterval(function(){
   x+=speedx;
   y+=speedy;
   oBox.style.WebkitTransform=' perspective(800px)'+' rotateY('+x/3+'deg)'+'rotateX('+-y/3+'deg)';
   speedx*=0.94;
   speedy*=0.94;
   if(Math.abs(speedx)<1)speedx=0;
   if(Math.abs(speedy)<1)speedy=0;
   if(speedx==0&&speedy==0){
    clearInterval(timer2)
   }
   },30);
   document.onmousemove=null;
   document.onmouseup=null;
  }
  };
  return false
 }
 </script>
</head>
<body>
<div class="box">
 <span>1</span>
 <span>2</span>
 <span>3</span>
 <span>4</span>
 <span>5</span>
 <span>6</span>
 <span>7</span>
 <span>8</span>
 <span>9</span>
 <span>10</span>
 <span>11</span>
 <span>12</span>
</div>
</body>
</html>

效果圖:

JavaScript制作3D旋轉(zhuǎn)相冊

可用鼠標拖動。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

網(wǎng)頁標題:JavaScript制作3D旋轉(zhuǎn)相冊
文章起源:http://muchs.cn/article12/ijcddc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、小程序開發(fā)、商城網(wǎng)站、網(wǎng)站設(shè)計公司軟件開發(fā)、域名注冊

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管