【问题标题】:Have page auto-scroll - but stop auto scrolling when the user manually scrolls (jquery?)有页面自动滚动 - 但是当用户手动滚动时停止自动滚动(jquery?)
【发布时间】:2014-11-12 06:02:06
【问题描述】:

不确定最好的方法。

我有一些代码可以自动滚动,如下所示:

$("html, body").animate({
    scrollTop: $('html, body').get(0).scrollHeight
}, (60000));

我认为我可以通过添加以下内容来“停止”这种滚动:

$(window).on('scroll', function() {
    $("html, body").stop();
});

但看起来当第一段代码执行时第二段代码正在触发。所以我什么也没做。

当用户想要手动滚动或移动滚动条时,我只需要一种方法来停止自动滚动。

欢迎所有想法。谢谢。

【问题讨论】:

    标签: jquery angularjs


    【解决方案1】:
    $('body,html').bind('scroll mousedown wheel DOMMouseScroll mousewheel keyup', function(e){
     if ( e.which > 0 || e.type == "mousedown" || e.type == "mousewheel"){
      $("html,body").stop();
     }
    });
    

    我找到了你的答案

    How can I differentiate a manual scroll (via mousewheel/scrollbar) from a Javascript/jQuery scroll?

    我已经添加了jsbin来描述

    http://jsbin.com/dujuxihota/1/edit?js,output

    【讨论】:

    • 我还有一个问题。我正在使用此代码:$("html, body").animate({ scrollTop: $('html, body').get(0).scrollHeight }, 6000);,但 6 秒后它仍未达到底部。我有一个 setInterval 在 6 秒后更改页面,因此在 6 秒结束之前滚动到达底部非常重要。我使用的代码有问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多