javascript - 使用 anchor 链接和 jquery 在部分之间跳转

标签 javascript jquery html css

我有一个使用 anchor 链接进行平滑滚动的代码,但我想要的是在窗口高度上创建一个固定链接,并在页面中可用的每个部分之间跳转。我的链接显示滚动了解更多。当用户点击时,它必须转到每个部分。到目前为止我的代码是:

$("#over_scroll_text a").on('click', function(event) {

    // Make sure this.hash has a value before overriding default behavior
    //if (this.hash == "") {
      // Prevent default anchor click behavior
      event.preventDefault();

      // Store hash
      //var hash = this.hash;

      // Using jQuery's animate() method to add smooth page scroll
      // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
      $('html, body').animate({
        //scrollTop: $(hash).offset().top
        scrollTop: $(document).height() - $(window).height()
      //}, 800//, function(){

        // Add hash (#) to URL when done scrolling (default click behavior)
        //window.location.hash = hash;
      });
    //} // End if
});

不知道我能从这里做什么。有帮助吗?

最佳答案

第 9、16 和 19 行不应被注释掉

关于javascript - 使用 anchor 链接和 jquery 在部分之间跳转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51851079/

相关文章:

javascript - 是否可以更精细地控制 jQuery UI Dialog Widget 的显示/隐藏方法?

css - 将样式与 dom 操作分离的策略

javascript - 如何从对象数组中获取特定的 JSON 元素 (jQuery)

javascript - 悬停时并排显示三个 Div

javascript - 如何在其他div中显示输入的数据?

html - 如何在页面的左上角和右上角放置两个 anchor 标记,在覆盖页面的 div 中,并在另一个 div 之外?

java - 如何让我的网站检查访问者的 java 安装并提供更新或安装?

javascript - 如何在 React 中的切换开关组件内添加文本?

javascript - 使用 Angular js 在前端下载文件

html - Flexbox,移动响应式