js无缝滚动代码 为何停止
<scripttype="text/javascript">functionmarquee(){div2.innerHTML=div1.innerHTML;if(div2...
<script type="text/javascript">
function marquee()
{
div2.innerHTML=div1.innerHTML;
if(div2.offsetTop-bigdiv.scorllTop<=0)
bigdiv.scrollTop-=div1.offsetHeight;
else
bigdiv.scrollTop++;
}
var ooo = setInterval(marquee, 60)
bigdiv.onmouseover=function() {clearInterval(ooo) }
bigdiv.onmouseout=function() {ooo = setInterval(marquee, 60) }
</script>
为什么滚一会就停止了。 展开
function marquee()
{
div2.innerHTML=div1.innerHTML;
if(div2.offsetTop-bigdiv.scorllTop<=0)
bigdiv.scrollTop-=div1.offsetHeight;
else
bigdiv.scrollTop++;
}
var ooo = setInterval(marquee, 60)
bigdiv.onmouseover=function() {clearInterval(ooo) }
bigdiv.onmouseout=function() {ooo = setInterval(marquee, 60) }
</script>
为什么滚一会就停止了。 展开
2个回答
展开全部
if(div2.offsetTop-bigdiv.scorllTop<=0)
这里的scorllTop拼写错了,应该是scrollTop.
试了一下,没发现你说的问题,但上面的错误也可导至不滚动.测试通过的代码如下:
<body>
<div id="bigdiv" style="width:200px; height:200px; overflow:hidden;">
<div id="div1"><img src="" style="width:100;"><img src="" style="width:100;"><img src="" style="width:100;"><img src="" style="width:100;"><img src="" style="width:100;"></div>
<div id="div2"></div>
</div>
<script type="text/javascript">
function marquee(){
div2.innerHTML=div1.innerHTML;
if(bigdiv.scrollTop>=div2.offsetHeight)
bigdiv.scrollTop-=div1.offsetHeight;
else
bigdiv.scrollTop++;
}
var ooo = setInterval(marquee, 60)
bigdiv.onmouseover=function() {clearInterval(ooo) }
bigdiv.onmouseout=function() {ooo = setInterval(marquee, 60) }
</script>
</body>
这里的scorllTop拼写错了,应该是scrollTop.
试了一下,没发现你说的问题,但上面的错误也可导至不滚动.测试通过的代码如下:
<body>
<div id="bigdiv" style="width:200px; height:200px; overflow:hidden;">
<div id="div1"><img src="" style="width:100;"><img src="" style="width:100;"><img src="" style="width:100;"><img src="" style="width:100;"><img src="" style="width:100;"></div>
<div id="div2"></div>
</div>
<script type="text/javascript">
function marquee(){
div2.innerHTML=div1.innerHTML;
if(bigdiv.scrollTop>=div2.offsetHeight)
bigdiv.scrollTop-=div1.offsetHeight;
else
bigdiv.scrollTop++;
}
var ooo = setInterval(marquee, 60)
bigdiv.onmouseover=function() {clearInterval(ooo) }
bigdiv.onmouseout=function() {ooo = setInterval(marquee, 60) }
</script>
</body>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询