时间:2021-05-26
本文实例讲述了JS实现文字掉落效果的方法。分享给大家供大家参考。具体实现方法如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru"><head><title></title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script src="jquery-1.6.2.min.js" type="text/javascript"></script><style type="text/css">.canvas{width:500px;height:500px;position:relative;}</style></head><body><div><input type="button" onclick="javascript:falling.init();" value="GO" /></div><div class="canvas" id="canvas"></div><script type="text/javascript">/**坠落效果*/function Falling(){ this.dict=["abcd","2222","sign","next","container","content","last","break","less","than","that","absolute","relative","my","index","html","java","c#","web","javascript","php","include","shit","bull","big","smart","call","apply","callee","caller","function"]; this.canvas=$("#canvas"); this.step=15; this.freq=10; this.height=500; this.width=500; this.si=null;}Falling.prototype={ fallingAction:function(dom){ var self=this; var freqs=[10,15,20];//每次下落的距离 var disS=[];//记录所有dom的当前距离 var disPerFreqS=[];//每个dom的 var targetDis=500; var domCssTopS=[];//所有dom的top属性 var successDom=[];//记录哪些dom已经结束运动 var successCount=0;//有多少个dom已经结束 var total=dom.length; var freqMarkLength=freqs.length; for(var i=0,j=dom.length;i<j;i++){ domCssTopS[i]=dom[i].position().top; disS[i]=0; disPerFreqS[i]=freqs[parseInt(Math.random()*freqMarkLength)]; } self.si=setInterval(function(){ if(successCount>=total){ clearInterval(self.si); } for(var i=0,j=dom.length;i<j;i++){ if(typeof(successDom[i])!="undefined" && successDom[i]=="ok"){ continue; } disS[i] += disPerFreqS[i]; if(disS[i] >= targetDis){ dom[i].css("top", targetDis+domCssTopS[i]); successDom[i]="ok"; successCount++;; }else{ dom[i].css("top", disS[i]+domCssTopS[i]); } } },self.freq); }, init:function(){ var self=this; self.canvas.html(''); var dom=[]; var l=0; var t=0; var tempDom=$("<div style='position;absolute;left:-100000;visibility:hidden'></div>").appendTo($("body")); for(var i=0,j=self.dict.length;i<j;i++){ dom[i]=$("<span style='position:absolute'>"+self.dict[i]+"</span>").appendTo(tempDom); var domWidth=dom[i].width(); var domHeight=dom[i].height(); if(t<self.height){ if(l<self.width){ if(domWidth+l<=self.width){ dom[i].css({"top":t,"left":l}); self.canvas.append(dom[i]); l += dom[i].width(); }else{ if(domHeight+t<=self.height){ t=t+domHeight; dom[i].css({"top":t,"left":0}); self.canvas.append(dom[i]); l = dom[i].width(); }else{ break;//到极限了 } } }else{ if(domHeight+t<=self.height){ t=t+domHeight; l=0; dom[i].css({"top":t,"left":l}); self.canvas.append(dom[i]); }else{ break;//到极限了 } } }//else极限 } self.fallingAction(dom); }}var falling=new Falling();falling.init();</script></body></html>希望本文所述对大家的javascript程序设计有所帮助。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了JS实现文字放大效果的方法。分享给大家供大家参考。具体实现方法如下:复制代码代码如下:JS实现文字放大效果varn=12;functionchan
想要制作一个创意十足的文字动画效果,该怎么制作呢?可以实现的软件很多,今日按我们就来看看使用ae制作酷炫的文字波浪掉落效果的教程。软件名称:AdobeAfter
本文实例讲述了js实现input框文字动态变换显示效果。分享给大家供大家参考。具体如下:这里演示js实现INPUT框中的特殊显示效果,一些文字慢慢交替显示,最终
ae中怎么制作沙漏文字效果呢?文字如同漏沙般减少,最后整个掉落。该怎么制作呢?下面我们就来看看详细的教程。软件名称:AdobeAfterEffectsCC201
本文实例讲述了JS实现超简洁网页title标题跑动闪烁提示效果代码。分享给大家供大家参考,具体如下:这里演示不几行JS代码实现的网页Title文字跑动效果,类似