国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

純JS實現旋轉圖片3D展示效果

2019-11-20 12:43:10
字體:
來源:轉載
供稿:網友

CSS:

<style type="text/css">#show{position:relative;margin:20px auto;width:800px;}.item{position:absolute;height:40px;width:60px;background:#999999;border:1px solid #eeeeee;cursor:pointer;}</style>

Html:

input id="l" type="button" value="left" /> <input id="r" type="button" value="right" /><div id="show"><div class="item">1</div><div class="item">2</div><div class="item">3</div><div class="item">4</div><div class="item">5</div><div class="item">6</div><div class="item">7</div><div class="item">8</div><div class="item">9</div><div class="item">0</div><div class="item">a</div><div class="item">b</div><div class="item">1</div><div class="item">2</div><div class="item">3</div></div>

JS

<script>var len;var showerObj;var listObj;var showerWidth=800;var showerHeight=400;var r;var cR=0;var ccR=0;var timer=0;window.onload=function(){ showerObj=document.getElementById("show"); listObj=showerObj.getElementsByTagName("div"); len=listObj.length; r=Math.PI/180*360/len; for(var i=0;i<len;i++){ var item=listObj[i]; item.style.top=showerHeight/2+Math.sin(r*i)*showerWidth/2-20+"px"; item.style.left=showerWidth/2+Math.cos(r*i)*showerWidth/2-30+"px"; item.rotate=(r*i+2*Math.PI)%(2*Math.PI); item.onclick=function(){  cR=Math.PI/2-this.rotate;  timer || (timer=setInterval(rotate,10));   }  } var rX=showerObj.offsetLeft+showerWidth/2; var ry=showerObj.offsetTop+showerHeight/2;  var rotate=function(){ ccR=(ccR+2*Math.PI)%(2*Math.PI); if(cR-ccR<0) cR=cR+2*Math.PI; if(cR-ccR<Math.PI){  ccR=ccR+(cR-ccR)/19; }else{  ccR=ccR-(2*Math.PI+ccR-cR)/19;  }  if(Math.abs((cR+2*Math.PI)%(2*Math.PI)-(ccR+2*Math.PI)%(2*Math.PI))<Math.PI/720){  ccR=cR;  clearInterval(timer);  timer=0; }  for(var i=0;i<len;i++){  var item=listObj[i];  var w,h;  var sinR=Math.sin(r*i+ccR);  var cosR=Math.cos(r*i+ccR);  w=60+0.6*60*sinR;  h=(40+0.6*40*sinR);  item.style.cssText +=";width:"+w+"px;height:"+h+"px;top:"+parseInt(showerHeight/2+sinR*showerWidth/2/3-w/2)+"px;left:"+parseInt(showerWidth/2+cosR*showerWidth/2-h/2)+"px;z-index:"+parseInt(showerHeight/2+sinR*showerWidth/2/3-w/2)+";";  } }  document.getElementById("l").onclick=function(){ cR=(cR+r+2*Math.PI)%(2*Math.PI); timer || (timer=setInterval(rotate,10)); } document.getElementById("r").onclick=function(){ cR=(cR-r+2*Math.PI)%(2*Math.PI); timer || (timer=setInterval(rotate,10)); } rotate();}</script>

以上所述就是本文的全部內容了,希望大家能夠喜歡。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 社旗县| 闸北区| 西乌珠穆沁旗| 波密县| 星子县| 鄂托克旗| 苍溪县| 鄂托克前旗| 类乌齐县| 白朗县| 新津县| 普陀区| 泌阳县| 城口县| 宽甸| 乌审旗| 桐庐县| 襄樊市| 柘城县| 辽宁省| 丹东市| 镇沅| 榕江县| 若羌县| 思茅市| 靖边县| 随州市| 偃师市| 九江县| 安泽县| 桂林市| 大宁县| 子长县| 双城市| 万山特区| 疏附县| 宝清县| 石嘴山市| 克什克腾旗| 普兰县| 康保县|