JQuery 文字无缝滚动
更新:HHH   时间:2023-1-7


 功能:文字无缝滚动 (向左+向上)

 

向左滚动:

Jquery代码:

 

<script language="javascript" type="text/javascript">

<!--

function scroll(obj) {

var tmp = (obj.scrollLeft)++;

//当滚动条到达右边顶端时

if (obj.scrollLeft==tmp) obj.innerHTML += obj.innerHTML;

//当滚动条滚动了初始内容的宽度时滚动条回到最左端

if (obj.scrollLeft>=obj.firstChild.offsetWidth) obj.scrollLeft=0;

}

var   t = setInterval("scroll(document.getElementById('scrollobj'))",40);


 $("#scrollobj").mouseover(function(){

clearInterval(t);  

});//鼠标经常时,停止滚动

  $("#scrollobj").mouseout(function(){

setInterval(t = setInterval("scroll(document.getElementById('scrollobj'))",40))

});//鼠标离开时,重新执行函数


//-->

</script>


HTML代码:

 

<DIV id="scrollobj"  style="white-space:nowrap;overflow:hidden;width:500px;"><span>这里是要滚动的内容</span></DIV>


向上滚动:

Jquery代码:

 

<script language="javascript">

var speed=30;

var demo2=document.getElementById("demo2");

var demo1=document.getElementById("demo1");

var demo=document.getElementById("demo");

demo2.innerHTML=demo1.innerHTML;

function Marquee(){

if(demo2.offsetTop-demo.scrollTop<=0){

   demo.scrollTop-=demo1.offsetHeight;

}

else{

   demo.scrollTop++;

}

}

var MyMar=setInterval(Marquee,speed);

demo. {clearInterval(MyMar)};

demo. {MyMar=setInterval(Marquee,speed)};

</script>


返回web开发教程...