javascript - 导航链接功能故障

标签 javascript html css

由于某种原因,我的各自部分的导航链接在我的投资组合模板网站上已停止运行。是否有一个快速的 JavaScript 或 JQuery 解决方案可以放入我的脚本部分,让它们再次发挥作用?

导航 anchor 标记示例

            <ul class="nav navbar-nav" id="main-menu">
                <li>
                    <a href="#page-profile">Profile</a>
                </li>
            </ul>

部分目标示例

<section id="page-profile" class="page-profile">
        <div class="container">
            <header class="section-header">
                <h2 class="section-title">Personal Profile</h2>
                <div class="spacer"></div>
                <p class="section-subtitle">About Me</p>
            </header>

最佳答案

使用 jQuery:

$("moveToSectionButtonSelector").click(function() {
    $('html, body').animate({
        scrollTop: $("#page-profile").offset().top
    }, 1000);
});

关于javascript - 导航链接功能故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46329240/

相关文章:

javascript - 撤消/重做从 DOM 中删除元素

javascript - jquery 完整日历 : callback 'after' the calendar has loaded completely

javascript - 有序列表中的 2 个不同标记

html - 带有距离的子菜单,悬停时关闭

javascript - 服务 worker 的推送事件未被调用

php - 缓存 PHP 简单 HTML DOM 解析器

javascript - 如何制作:hover appearance remain after click/focus in search bar

css - 在图像上定位的最佳方式

html - 在wordpress中将图像一个接一个地堆叠

javascript - 如何使关键字固定在中心,而左右部分靠近它?