首页 > 解决方案 > 菜单滚动问题

问题描述

我的锚链接滚动有问题。

正如你所看到的,它是跳跃/小故障,我不知道为什么以及在哪里寻找解决这个问题。(使用 WordPress、elementor 和这个函数来平滑滚动)。

我也尝试了“Page to Id”插件,但由于某种原因,即使我检查了阻止任何其他滚动脚本的选项,它也会变得更加跳跃并且有奇怪的行为。

任何帮助表示赞赏。谢谢你。

function smooth_scroll() {
?>
    <script>
        jQuery(document).ready(function($) {
        $(".page-id-27 ul.primary-menu.reset-list-style li 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 - 100
            }, 900);
            return false;
            } // End if
          });
        });
    </script>
<?php

}

标签: phpwordpressfunction

解决方案


显然滚动行为是由 TwentyTwenty WordPress 主题引起的。

TwentyTwenty 主题中实现的卷轴已损坏。为了解决这个问题,我使用了以下内容:

  1. 更新主题。
  2. 将以下代码添加到您的子主题 CSS: html {scroll-behavior: auto !important;}
  3. 安装“Page to ID”WordPress 插件并轻松处理您的滚动。

谢谢你们的帮助,我真的很感激。


推荐阅读