我有这个自动滚动 div 的代码。当我们将光标移到特定的 div 上时,它会停止滚动,从 div 中移除光标后,它会自动从同一位置开始。代码工作正常,但有时它不工作,任何人都可以解决这个问题吗?
ScrollRate = 20;
function scrollDiv_init() {
DivElmnt = document.getElementById('MyDivName');
ReachedMaxScroll = false;
DivElmnt.scrollTop = 0;
PreviousScrollTop = 0;
ScrollInterval = setInterval('scrollDiv()', ScrollRate);
}
function scrollDiv() {
if (!ReachedMaxScroll) {
DivElmnt.scrollTop = PreviousScrollTop;
PreviousScrollTop++;
ReachedMaxScroll = DivElmnt.scrollTop >= (DivElmnt.scrollHeight -
DivElmnt.offsetHeight);
} else {
ReachedMaxScroll = (DivElmnt.scrollTop == 0) ? false : true;
DivElmnt.scrollTop = PreviousScrollTop;
PreviousScrollTop--;
}
}
function pauseDiv() {
clearInterval(ScrollInterval);
}
function resumeDiv() {
PreviousScrollTop = DivElmnt.scrollTop;
ScrollInterval = setInterval('scrollDiv()', ScrollRate);
}
<html>
<body onLoad="scrollDiv_init()">
<div class="inner" id="MyDivName" onMouseOver="pauseDiv()"
onMouseOut="resumeDiv()">
...........elements like (P ,img etc)....
</div>
</html>