JS實(shí)現(xiàn)3D圖片旋轉(zhuǎn)展示效果代碼
本文實(shí)例講述了JS實(shí)現(xiàn)3D圖片旋轉(zhuǎn)展示效果代碼。分享給大家供大家參考。具體如下:
這是一段JavaScript代碼,圍繞成3D模型樣式的JavaScript圖片旋轉(zhuǎn)展示代碼,這里為了演示方便,將圖片替換成了數(shù)字,預(yù)留出了圖片的位置,這樣速度快些,會(huì)HTML的朋友都知道用時(shí)候該怎么做。本圖片旋轉(zhuǎn)需要手功控制,每點(diǎn)擊一下,圖片旋轉(zhuǎn)一次,很方便。
運(yùn)行效果截圖如下:
在線演示地址如下:
http://demo.jb51.net/js/2015/js-3d-pic-scroll-show-style-codes/
具體代碼如下:
<!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>圖片旋轉(zhuǎn)展示</title> <style> #show{position:relative;margin:20px auto;width:800px;border:1px solid #999999;} .item{position:absolute;height:40px;width:60px;background:#999999;border:1px solid #eeeeee;cursor:pointer;} </style> <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> </head> <body> <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> </body> </html>
希望本文所述對(duì)大家的JavaScript程序設(shè)計(jì)有所幫助。
- JavaScript圖片旋轉(zhuǎn)效果實(shí)現(xiàn)方法詳解
- JavaScript如何處理移動(dòng)端拍攝圖片旋轉(zhuǎn)問(wèn)題
- JS實(shí)現(xiàn)圖片旋轉(zhuǎn)動(dòng)畫(huà)效果封裝與使用示例
- js實(shí)現(xiàn)圖片旋轉(zhuǎn) js滾動(dòng)鼠標(biāo)中間對(duì)圖片放大縮小
- jQuery圖片旋轉(zhuǎn)插件jQueryRotate.js用法實(shí)例(附demo下載)
- 圖片旋轉(zhuǎn)、鼠標(biāo)滾輪縮放、鏡像、切換圖片js代碼
- javascript結(jié)合canvas實(shí)現(xiàn)圖片旋轉(zhuǎn)效果
- js實(shí)現(xiàn)圖片旋轉(zhuǎn)的三種方法
- 純JS實(shí)現(xiàn)旋轉(zhuǎn)圖片3D展示效果
- Exif.js圖片旋轉(zhuǎn)修正的方法
相關(guān)文章
JS實(shí)現(xiàn)一個(gè)列表中包含上移下移刪除等功能
一個(gè)項(xiàng)目,包括了一個(gè)列表頁(yè)其中包括在列表中實(shí)現(xiàn)上移,下移,刪除等功能,為了用戶(hù)體驗(yàn),操作均使用JS實(shí)現(xiàn)2014-09-09js圖片滾動(dòng)效果時(shí)間可隨意設(shè)定當(dāng)鼠標(biāo)移上去時(shí)停止
這篇文章主要介紹了js圖片滾動(dòng)效果時(shí)間可隨意設(shè)定當(dāng)鼠標(biāo)移上去時(shí)停止,需要的朋友可以參考下2014-06-06javascript解決innerText瀏覽器兼容問(wèn)題思路代碼
innerText瀏覽器兼容這塊始終都是一個(gè)問(wèn)題,下面與大家分享下使用javascript解決,感興趣的朋友可以參考下哈,希望對(duì)你有所幫助2013-05-05js 數(shù)組操作之pop,push,unshift,splice,shift
本篇文章主要介紹了js數(shù)組操作之pop,push,unshift,splice,shift。需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-01-01js實(shí)現(xiàn)的點(diǎn)擊超鏈顯示隱藏層
js實(shí)現(xiàn)的點(diǎn)擊超鏈顯示隱藏層...2007-05-05