敏敏国际论坛's Archiver

张敏 发表于 2005-2-17 19:38

用JavaScript实现上下文字滚动特效

<P><SPAN class=javascript id=text970>具体实现方法如下: <BR><BR><BR>(在需要添加该特效的网页具体位置中粘贴如下代码即可) <BR>[code]<script language=JavaScript><BR>var messages=new Array()<BR>messages[0]=\"<font color=#8000FF>欢迎光临赛迪网电脑应用频道!</font></a>\"<BR>messages[1]=\"<font color=#FB2500>这里有织网梦工厂</font></a>\"<BR>messages[2]=\"<font color=#FF0066F>是网页初学者的学习园地</font></a>\"<BR>messages[3]=\"<font color=#FF9900>这里冲浪指南针</font></a>\"<BR>messages[4]=\"<font color=#00CC33>是网络爱好者天天必来充电的地方</font></a>\"<BR>messages[5]=\"<font color=#000000>这里有…………有精彩的内容等着你</font></a>\"</SPAN></P><P><SPAN class=javascript><BR>var scrollerwidth=320<BR>var scrollerheight=100<BR>var scrollerbgcolor=\'#FFFFFF\'<BR>//下面的代码不要改动<BR>if (messages.length>1)<BR>i=2<BR>else<BR>i=0<BR>function move1(whichlayer){<BR>tlayer=eval(whichlayer)<BR>if (tlayer.top>0&amp;&amp;tlayer.top<=5){<BR>tlayer.top=0<BR>setTimeout(\"move1(tlayer)\",3000)<BR>setTimeout(\"move2(document.main.document.second)\",3000)<BR>return}<BR>if (tlayer.top>=tlayer.document.height*-1){<BR>tlayer.top-=5<BR>setTimeout(\"move1(tlayer)\",100)}<BR>else{<BR>tlayer.top=scrollerheight<BR>tlayer.document.write(messages<i>)<BR>tlayer.document.close()<BR>if (i==messages.length-1)<BR>i=0<BR>else<BR>i++}}<BR>function move2(whichlayer){<BR>tlayer2=eval(whichlayer)<BR>if (tlayer2.top>0&amp;&amp;tlayer2.top<=5){<BR>tlayer2.top=0<BR>setTimeout(\"move2(tlayer2)\",3000)<BR>setTimeout(\"move1(document.main.document.first)\",3000)<BR>return}<BR>if (tlayer2.top>=tlayer2.document.height*-1){<BR>tlayer2.top-=5<BR>setTimeout(\"move2(tlayer2)\",100)}<BR>else{<BR>tlayer2.top=scrollerheight<BR>tlayer2.document.write(messages<i>)<BR>tlayer2.document.close()<BR>if (i==messages.length-1)<BR>i=0<BR>else<BR>i++}}<BR>function move3(whichdiv){<BR>tdiv=eval(whichdiv)<BR>if (tdiv.style.pixelTop>0&amp;&amp;tdiv.style.pixelTop<=5){<BR>tdiv.style.pixelTop=0<BR>setTimeout(\"move3(tdiv)\",3000)<BR>setTimeout(\"move4(second2)\",3000)<BR>return}<BR>if (tdiv.style.pixelTop>=tdiv.offsetHeight*-1){<BR>tdiv.style.pixelTop-=5<BR>setTimeout(\"move3(tdiv)\",100)}<BR>else{<BR>tdiv.style.pixelTop=scrollerheight<BR>tdiv.innerHTML=messages<i><BR>if (i==messages.length-1)<BR>i=0<BR>else<BR>i++}}<BR>function move4(whichdiv){<BR>tdiv2=eval(whichdiv)<BR>if (tdiv2.style.pixelTop>0&amp;&amp;tdiv2.style.pixelTop<=5){<BR>tdiv2.style.pixelTop=0<BR>setTimeout(\"move4(tdiv2)\",3000)<BR>setTimeout(\"move3(first2)\",3000)<BR>return}<BR>if (tdiv2.style.pixelTop>=tdiv2.offsetHeight*-1){<BR>tdiv2.style.pixelTop-=5<BR>setTimeout(\"move4(second2)\",100)}<BR>else{<BR>tdiv2.style.pixelTop=scrollerheight<BR>tdiv2.innerHTML=messages<i><BR>if (i==messages.length-1)<BR>i=0<BR>else<BR>i++}}<BR>function startscroll(){<BR>if (document.all){<BR>move3(first2)<BR>second2.style.top=scrollerheight}<BR>else if (document.layers){<BR>move1(document.main.document.first)<BR>document.main.document.second.top=scrollerheight+5<BR>document.main.document.second.visibility=\'show\'}}<BR>window.onload=startscroll<BR></script><BR><ilayer id=\"main\" width=&amp;{scrollerwidth}; height=&amp;{scrollerheight};<BR>bgcolor=&amp;{scrollerbgcolor};><BR><layer id=\"first\" left=0 top=1 width=&amp;{scrollerwidth};><BR><script language=\"JavaScript1.2\"><BR>if (document.layers)<BR>document.write(messages[0])<BR></script><BR></layer><BR><layer id=\"second\" left=0 top=0 width=&amp;{scrollerwidth}; visibility=hide><BR><script language=\"JavaScript1.2\"><BR>if (document.layers)<BR>document.write(messages[1])<BR></script><BR></layer><BR></ilayer><BR><script language=\"JavaScript1.2\"><BR>if (document.all){<BR>document.writeln(\'<span id=\"main2\" style=\"position:relative;width:\'+scrollerwidth+\';height:\'<BR>+scrollerheight+\';overflow:hiden;background-color:\'+scrollerbgcolor+\'\">\')<BR>document.writeln(\'<div style=\"position:absolute;width:\'+scrollerwidth+\';height:\'<BR>+scrollerheight+\';clip:rect(0 \'+scrollerwidth+\' \'<BR>+scrollerheight+\' 0);left:0;top:0\">\')<BR>document.writeln(\'<div id=\"first2\" style=\"position:absolute;width:\'+scrollerwidth+\';left:0;top:1;\">\')<BR>document.write(messages[0])<BR>document.writeln(\'</div>\')<BR>document.writeln(\'<div id=\"second2\" style=\"position:absolute;width:\'+scrollerwidth+\';left:0;top:0\">\')<BR>document.write(messages[1])<BR>document.writeln(\'</div>\')<BR>document.writeln(\'</div>\')<BR>document.writeln(\'</span>\')<BR>}<BR></script></SPAN><SPAN class=javascript>[/code]</SPAN></P>

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.