wordpress - 如何在wordpress的页面模板上使用页面滚动到id插件?
问题描述
我有通过在 wordpress 中使用多个小模板页面创建的主页。我在上面设置了菜单。现在我想使用菜单继续特定部分/模板。就像我按下联系人菜单按钮一样,它应该会顺利向下移动到调用联系人模板的主页。我正在使用 wordpress 的“页面滚动到 id”插件,但它不起作用。当页面由仪表板页面创建时,我还看到这个插件工作。请帮助我,我如何使用这个插件导航到我的模板页面/部分。如果还有其他插件,请告诉我。我也会尝试使用它。
谢谢
解决方案
要在链接上创建平滑滚动,请单击以下步骤:
第 1 步:在菜单 href 中添加部分 ID,包括来自 admin section 的 #section1 Appearance >> Menu
。
第 2 步:创建 id 名称为 section1 的部分或 div。
<div id="section1"></div>
第 3 步:将以下代码粘贴到您的自定义 js 文件下。
$(document).ready(function(){
// Add smooth scrolling to all links
$("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
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
} // End if
});
});
我希望它会帮助你。
推荐阅读
- javascript - 在 react-ace Ace Editor 中将多行字符串设置为 defaultValue
- git - 推送后可以重写 Github 拉取请求吗?
- python-3.x - 我正在使用开放式简历,我正面临这个错误
- c# - 转换/投射任务
> 到基础类型 - python - 如何在没有验证的情况下调用模型?
- python - Python Django:Django 不会从静态之外的文件夹中渲染图像
- jsf - 目标不可达,标识符 '
' 在 JSF 3.0 中解析为 null - javascript - 如何检测远程对等点何时禁用 WebRTC 中的跟踪?
- javascript - 每次路由更改时如何在angularJS中执行ng-init
- c++ - C++ 意外输出