php - 菜单滚动问题
问题描述
我的锚链接滚动有问题。
正如你所看到的,它是跳跃/小故障,我不知道为什么以及在哪里寻找解决这个问题。(使用 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
}
解决方案
显然滚动行为是由 TwentyTwenty WordPress 主题引起的。
TwentyTwenty 主题中实现的卷轴已损坏。为了解决这个问题,我使用了以下内容:
- 更新主题。
- 将以下代码添加到您的子主题 CSS: html {scroll-behavior: auto !important;}
- 安装“Page to ID”WordPress 插件并轻松处理您的滚动。
谢谢你们的帮助,我真的很感激。
推荐阅读
- javascript - 处理 Google Place Api 时出错。如果 api 键被限制输入变为空白
- mysql - 在 Mysql 数据库中存储列表
- python - 如何使用 Django 在 Python 中切换 HTML 页面
- python - EOFError:用尽输入(CNN 模型)
- ruby-on-rails - Ruby on Rails 5 中的 includes(:associations).references(:associations) 和 eager_load(:associations) 之间有什么区别吗?
- html - 在具有相同名称的多个 html 标记之间进行抓取
- swift - SwiftUI Nested ForEach 导致意外排序
- java - 出现错误“数据库中已经有一个名为‘abc’的对象。” 即使在保持 hibernate.ddl-auto 值更新之后
- jquery - 基于所选选项显示/隐藏 div 元素的动态 jQuery 下拉列表
- python - 编译 boost 时的地址模型错误