Py学习  »  Jquery

jQuery在不同页面上平滑滚动以定位

James Leavitt • 4 年前 • 259 次点击  

如果一个元素链接到同一页上的锚定,那么jQuery smooth scroll可以工作,但是当链接到另一页上的锚定时,它不会平滑滚动。

我的jQuery脚本有什么明显的问题吗?

<script>
jQuery(function($) {

    // //////////////////////// Smooth Scroll To Specific Element On Page ////////////////////////

    $(document).ready(function() {
        $('a[href^="#"]').not('.carousel-control-prev').not('.carousel-control-next').bind('click.smoothscroll', function(e) {
            e.preventDefault();

            var hash = this.hash;

            jQuery('html, body').animate({
                scrollTop: jQuery(hash).offset().top - 65
            }, 1500, function(){});
        });
    });

    //////////////////////// Smooth Scroll To Specific Element On Different Page ////////////////////////

    $(document).ready(function(){
        var urlHash = window.location.href.split("#")[1] || false;
        if (urlHash.length > 0)
            $('html,body').animate({
                scrollTop: $('#' + urlHash).offset().top - 60
            }, 2500);
    });

});
</script>
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52197
 
259 次点击  
文章 [ 1 ]  |  最新文章 4 年前