Javascript 为什么scrollTop只向下滚动了一半?

Javascript 为什么scrollTop只向下滚动了一半?,javascript,jquery,scrolltop,Javascript,Jquery,Scrolltop,我在jQuery代码段上有一个错误,我不是jQuery专家。我有一个滚动div将自动滚动以下功能 // When DOM is fully loaded jQuery(document).ready(function ($) { function scroll(speed) { $('.shooter-scroller').animate({ scrollTop: $(document).height() - $('.shooter-scroll

我在jQuery代码段上有一个错误,我不是jQuery专家。我有一个滚动div将自动滚动以下功能

// When DOM is fully loaded
jQuery(document).ready(function ($) {

    function scroll(speed) {
        $('.shooter-scroller').animate({
            scrollTop: $(document).height() - $('.shooter-scroller').height()
        }, fast, function () {
            $(this).animate({
                scrollTop: 0
            }, speed);
        });
    }

    speed = 15000;

    scroll(speed)
    setInterval(function () {
        scroll(speed)
    }, speed * 2);
});
我需要用这个脚本做两件事,但如果人们能帮我的话,我希望能得到一些帮助

由于某些原因,滚动在div的一半停止,并且没有显示div中的所有内容,我想让滚动在到达底部后重置回内容的顶部。这可能吗

任何帮助都将是惊人的

小提琴:


提前感谢。

要想找到底部,你必须给出滚动顶部作为元素的高度

// When DOM is fully loaded
jQuery(document).ready(function ($) {

    function scroll(speed) {
        $('.shooter-scroller').animate({
            scrollTop: $('.shooter-scroller').prop("scrollHeight")
        }, fast, function () {
            $(this).animate({
                scrollTop: 0
            }, speed);
        });
    }

    speed = 15000;

    scroll(speed)
    setInterval(function () {
        scroll(speed)
    }, speed * 2);
});
这将获得滚动高度。

您需要更改

$(document).height() - $('.shooter-scroller').height()

这会给你正确的高度。
请参阅(注意:为了获得更清晰的结果,我更改了速度)

您能提供一个提琴或至少是html吗?嗨,对不起,下面是提琴。这很好用。有没有办法让它在到达底部后直接反弹到顶部,而不是向上滚动?顺便谢谢你的帮助!当然,只需将动画更改为
this.scrollTop=0出于好奇……卷轴似乎开始缓慢,然后加速,有什么办法可以阻止它吗?默认的放松模式是swing(),您可以将其更改为
线性
,使其不断以相同的速度移动。
$('.shooter-scroller').prop('scrollHeight')