网页中实现文字或图片向上不间断滚动的javascript代码

参考网址:http://www.discuz.net/thread-265541-1-1.html

<html>
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" οnlοad="init_srolltext();" bgcolor="#fafafa">
<div id="icefable1">
         <table>
             <tr><td>
<!--下面为滚动显示的内容,可以用图片框或文本框替换,如<img src="..." height="164" width="251" border="0">-->
<font color=#3A5FCD size=2 face=黑体>【名言警句】一个人最伤心的事情无过于良心的死灭。 —— 郭沫若</font>
         </td></tr></table>

<!--这里产生了间隙-->
         <table>
             <tr><td>
<font color=#0000FF size=2 face=黑体>【名言警句】不要慨叹生活底痛苦!---慨叹是弱者...... —— 高尔基</font>
         </td></tr></table>


      <table >
             <tr><td>
<font color=#8B0A50 size=2 face=黑体>【名言警句】希望是附丽于存在的,有存在,便有希望,有希望,便是光明。 —— 鲁迅</font>
         </td></tr></table>   
        
        
         </div>

<script type="text/javascript" language="javascript">
marqueesHeight=24; //因为有间隙存在,这里的高度一定要设置的比图片框或文字框的高度要大,否则将
//无法连续滚动(如上文若为<img src="..." height="164" width="251" border="0">的图片框时,这里一
//定要设置的比164要大,这里因为没有文字框或图片框,所以才设置为24)
stopscroll=false;
with(icefable1){
style.width=0;
style.height=marqueesHeight;
style.overflowX="visible";
style.overflowY="hidden";
noWrap=true;
οnmοuseοver=new Function("stopscroll=true");
οnmοuseοut=new Function("stopscroll=false");
}
preTop=0; currentTop=marqueesHeight; stoptime=0;
icefable1.innerHTML+=icefable1.innerHTML;


function init_srolltext(){
icefable1.scrollTop=0;
setInterval("scrollUp()",20);
}init_srolltext();

function scrollUp(){
if(stopscroll==true) return;
currentTop+=1;
if(currentTop==(marqueesHeight+1))
{
   stoptime+=1;
   currentTop-=1;
   if(stoptime==300) //停留时间设置为300秒
   {
currentTop=0;
stoptime=0;    
   }
}
else {
preTop=icefable1.scrollTop;
icefable1.scrollTop+=1;      //scrollTop是图片框的高度,达到scrollTop以后再增加1也还是scrollTop了
//(测试出来的结果)
if(preTop==icefable1.scrollTop){
icefable1.scrollTop=marqueesHeight;
icefable1.scrollTop+=1;

}
}

}

</script></body></html>

ps:对参考资料中的原文做了一点点的修改,所以设定为了原创。以此文纪念和感谢BX对此项知识做出的贡献,要知道为了那个marqueesHeight的设置,我和BX搞到了凌晨,而且还是在寒冷的冬夜,没吃晚饭的冬夜:-((。最后郑重声明:本文仅供个人学习使用。

 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值