Home > Web Front-end > JS Tutorial > JS simulated paper tearing effect of Tencent Weibo app example code_javascript skills

JS simulated paper tearing effect of Tencent Weibo app example code_javascript skills

WBOY
Release: 2016-05-16 17:33:38
Original
1079 people have browsed it

[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]<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>
Related labels:
app
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template