scrolltop在centos上不起作用

scrolltop does not work on centos

本文关键字:不起作用 centos scrolltop      更新时间:2023-09-26

我正试图让点击按钮时滚动变得平滑。它可以很好地与本地apache服务器和IE10+配合使用。但当部署在"centos"上的项目中时,它不能在同一个浏览器上工作。没有生成错误。有人能帮我找出这背后的原因吗?

    $(document).ready(function() {
    //+ Scroll smoothly to the target href.
    $("#btnGenerate").click(function(e){
        e.preventDefault();
        var offset = $( $.attr(this, 'href') ).offset().top;
        if (offset == 0)
        {
            offset = 230;
        }
        $("html, body").animate({
            scrollTop: offset
            },
            1000,
            function () {
                alert('animation complete.');
            }
        );
    });
    //-
});

HTML:

<input id="btnGenerate" href="#labelFirstChart" type="button" value="Generate"/>

这应该适用于具有锚链接的元素:

$('a[href^=#]').on('click', function(e){
    e.preventDefault();
    var href = $(this).attr('href');
    $('html, body').animate({ 
        scrollTop:$(href).offset().top
    },'slow');
});

这里有一个例子:

http://codepen.io/acki/pen/wMGaPB