当前位置: 代码迷 >> Web前端 >> 通知公告 下上循环滚动
  详细解决方案

通知公告 下上循环滚动

热度:371   发布时间:2012-11-20 09:55:43.0
通知公告 上下循环滚动
代码一:

<div id=design style="OVERFLOW: hidden; WIDTH: 248px; HEIGHT: 237px;">
<div id=design1 style="OVERFLOW: hidden">

滚动内容


</div>
<div id=design2>
</div>
</div>
<script>
var speed=30
design2.innerHTML=design1.innerHTML
function Marquee2()
{
if(design2.offsetTop-design.scrollTop<=0)
design.scrollTop-=design1.offsetHeight
else
{
design.scrollTop++
}
}
var MyMar2=setInterval(Marquee2,speed)
design.onmouseover=function()
{
clearInterval(MyMar2)
}
design.onmouseout=function()
{
MyMar2=setInterval(Marquee2,speed)
}
</script>

 

代码二:

<div id="marquees">

<!--

滚动内容

-->

</div>

<script language="JavaScript">

marqueesHeight=160;

stopscroll=false;

with(marquees){

style.width=0;

style.height=marqueesHeight;

style.overflowX="visible";

style.overflowY="hidden";

noWrap=true;

onmouseover=new Function("stopscroll=true");

onmouseout=new Function("stopscroll=false");

}

document.write('<div id="templayer" style="position:absolute;z-index:1;visibility:hidden"></div>');

preTop=0; currentTop=0;

function init(){

templayer.innerHTML="";

while(templayer.offsetHeight<marqueesHeight){

    templayer.innerHTML+=marquees.innerHTML;

}

marquees.innerHTML=templayer.innerHTML+templayer.innerHTML;

setInterval("scrollUp()",30);

}

document.body.onload=init;

function scrollUp(){

if(stopscroll==true) return;

preTop=marquees.scrollTop;

marquees.scrollTop+=1;

if(preTop==marquees.scrollTop){

    marquees.scrollTop=templayer.offsetHeight-marqueesHeight;

    marquees.scrollTop+=1;

}

}

</script>
?
  相关解决方案