手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >纯JS实现旋转图片3D展示效果
纯JS实现旋转图片3D展示效果
摘要:CSS:#show{position:relative;margin:20pxauto;width:800px;}.item{positio...

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>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> <div>6</div> <div>7</div> <div>8</div> <div>9</div> <div>0</div> <div>a</div> <div>b</div> <div>1</div> <div>2</div> <div>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>

以上所述就是本文的全部内容了,希望大家能够喜欢。

【纯JS实现旋转图片3D展示效果】相关文章:

JS+CSS实现的拖动分页效果实例

javascript实现图片跟随鼠标移动效果的方法

JS实现模拟风力的雪花飘落效果

JavaScript实现带标题的图片轮播特效

对联浮动广告效果

jQuery实现首页图片淡入淡出效果的方法

JS函数实现鼠标指向图片后显示大图代码

JS实现定时自动关闭DIV层提示框的方法

js实现精美的图片跟随鼠标效果实例

Nodejs实现批量下载妹纸图

精品推荐
分类导航