我将如何获取此.scrollTop代码并对其进行修改以在鼠标悬停或滚动时暂停其功能

How would I take this .scrollTop code and modify it to pause it's function on Mouse Hover or Scrolling?

本文关键字:修改 鼠标 悬停 功能 暂停 滚动 何获取 获取 代码 scrollTop      更新时间:2023-09-26
<script>
window.setInterval(function() {
var elem = document.getElementById('onDiv');
elem.scrollTop = elem.scrollHeight;
}, 5000, 'swing');
</script>
<div id="onDiv" align="center" style="width:100%; height:250px; overflow:auto; padding-left: 2px;">
     <table id="asdf" cellspacing="0" cellpadding="0" border="0" width="100%" style="min-height:250px; overflow:auto; max-height:250px; padding-left: 2px;" >
       <tr>
         <td height="250" valign="top">Content</td>
       </tr>
     </table>

 </div>

上面的代码设置为每 5 秒向下滚动到底部,每个添加到div 的新内容。

我对使用jQuery相对较新,所以这里可能有一些不正确的格式。只是抬头。

谢谢大家/女孩!

reyaner 给出的这段代码似乎是我想做的,但我无法让它在当前声明中工作。

<script>
var IV;
function setInterval(){
IV = window.setInterval(function() {
    var elem = document.getElementById('onDiv');
    elem.scrollTop = elem.scrollHeight;
}, 1000, 'swing');
}
setInterval();
("#onDiv").hover(function(){
clearInterval(IV);
}, function(){
setInterval();
});
</script>

这行得通吗?

 var IV;
    function mysetInterval() {
        IV = setInterval(function() {
            var elem = document.getElementById('onDiv');
            elem.scrollTop = elem.scrollHeight;
        }, 1000);
    }
    mysetInterval();
    $(function() {
        $("#onDiv").hover(function() {
            clearInterval(IV);
        }, function() {
            mysetInterval();
        });
    });

像这样的东西:(在函数中复制了你的代码。

var IV;
function setInterval(){
    IV = window.setInterval(function() {
        var elem = document.getElementById('onDiv');
        elem.scrollTop = elem.scrollHeight;
    }, 5000, 'swing');
}
setInterval();
$("element").hover(function(){
    clearInterval(IV);
}, function(){
    setInterval();
});

看看这个:http://jsfiddle.net/balintbako/Xn9gd/

var interval;
$("#onDiv").hover(function () {
    $(this).stop(true);
    clearInterval(interval);
}, function () {
    queue();
});
function queue() {
    interval = setInterval(function () {        
        $("#onDiv").animate({
            scrollTop: $("#onDiv").prop('scrollHeight')
        }, 1000);
    }, 500);
}
queue();