scrollTop jQuery无法正常工作:/

时间:2017-04-21 00:53:43

标签: jquery scrolltop

我的函数scrollTop有问题。当点击.scrollToComment时,我尝试将滚动设置为#comment,但不知道为什么它不起作用...

头:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js?ver=3.2.1"></script>

和滚动代码:

$(".scrollToComment").click(function() {
$('html, body').animate({
scrollTop: $("#comment").offset().top
}, 2000);
});

问题在于我开始新的小项目: http://katalogliquidow.mrqzi.webd.pl/

请帮助。

1 个答案:

答案 0 :(得分:1)

替换您的代码以进行滚动

<script>
    $(document).on('click','.scrollToComment',function(){
        $('html, body').animate({
            scrollTop: $("#comment").offset().top
        }, 2000);
    });
</script>

它适用于我

干杯