首页 > 解决方案 > 导航中的 JQuery 平滑滚动

问题描述

我浏览了很多关于此的其他帖子,并尝试解决这个问题,无论出于何种原因它仍然无法正常工作:

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>
    $(document).ready(function() {
        $("a").on("click", function(event) {
            var hash = $(this).data("hash");
            if (hash) {
                $("html, body").animate({
                    scrollTop: $(document.getElementById(hash)).offset().top
                }, 800, function() {
                    window.location.hash = hash;
                });
            }
        });
    });

</script>
</head>
<body>
    <div class="nav-bar-in">
    <ul>
        <li><a href="/Home" class="active">Home</a></li>
        <li><a href="/Start">Start</a></li>
        <li><a href="#more">More</a></li>
    </ul>
</div>

<a name="more"></a>

标签: jquery

解决方案


推荐阅读