首頁 >web前端 >js教程 >JS模擬的騰訊微博app撕紙效果的實例代碼_javascript技巧

JS模擬的騰訊微博app撕紙效果的實例代碼_javascript技巧

WBOY
WBOY原創
2016-05-16 17:33:381080瀏覽

[Ctrl A 全選 註:如需引入外部Js需刷新才能執行
]<script> function $(id){/* 获取id */ return typeof id === "string" ? document.getElementById(id) : id; } function getStyle(obj, attr){ return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj, false)[attr]; } function startMove(obj, json, fnEnd){ if(obj.timer){ clearInterval(obj.timer); } obj.timer=setInterval(function (){ doMove(obj, json, fnEnd); }, 10); var oDate=new Date(); if(oDate.getTime()-obj.lastMove>30){ doMove(obj, json, fnEnd); } } function doMove(obj, json, fnEnd){ var iCur=0; var attr=''; var bStop=true;//假设运动已经该停止了 for(attr in json){ iCur = attr=='opacity'?parseInt(100*parseFloat(getStyle(obj, 'opacity'))):parseInt(getStyle(obj, attr)); if(isNaN(iCur)){ iCur=0; } var iSpeed=(json[attr]-iCur)/8; iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed); if(parseInt(json[attr])!=iCur){ bStop=false; } if(attr=='opacity'){ obj.style.filter="alpha(opacity:"+(iCur+iSpeed)+")"; obj.style.opacity=(iCur+iSpeed)/100; } else{ obj.style[attr]=iCur+iSpeed+'px'; } } if(bStop){ clearInterval(obj.timer); obj.timer=null; if(fnEnd){ fnEnd(); } } obj.lastMove=(new Date()).getTime(); } var flag = 0; $('content').onclick = function(ev){ var oEvent=ev||event; if(!flag){ var Y = oEvent.clientY-25; Y = Y<0?0:Y; Y = Y>350?350:Y; $('bg_sizhi').style.top = $('mack').style.top = Y+'px'; $('content_mack').style.top = -Y+'px'; startMove($('mack'),{'left':-300}); flag = 1; }else{ startMove($('mack'),{'left':0}); flag = 0; } } </script>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn