javascript - Scrollify (jquery) - 在站点的某些页面上禁用插件(新手)
问题描述
我正在尝试在我的网站(Wordpress,woocomerce)www.chame-lemon.com上使用 scrollify,而且我在编程方面完全是绿色的,所以我真的需要你们的帮助。
我需要禁用商店页面和产品页面上的插件,当我想使用插件时,我对页面上的所有部分都使用了一个名为“hwdp”的类。但是由于页脚(它也有一个可以打开滚动的类),他在其他页面上被激活但是我不能在 Wordpress 中使用两个单独的页脚,所以我需要使用带有函数的代码
$.scrollify.disable();
The disable method turns off the scroll snap behavior so that the page scroll like normal.
该插件有文档 https://projects.lukehaas.me/scrollify/#methods-continued
应该是这样的:如果页面上没有名为 hwdp 的类,则应禁用该插件,否则应启用该插件
我试图自己解决这个问题,我花了几个小时但没有得到任何结果......而且我知道这对于了解 jquery 的人来说是一件非常简单的事情。
<script>
jQuery(document).ready(function($) {
$.scrollify({
section : ".hwdp",
interstitialSection: ".footer",
easing: "easeOutExpo",
scrollSpeed: 1200,
offset: 1,
scrollbars: true,
standardScrollElements: "",
setHeights: true,
overflowScroll: true,
updateHash: true,
touchScroll: false,
before:function() {},
after:function() {},
afterResize:function() {},
afterRender:function() {},
});
if (!$('section').hasClass('.hwdp')) {
$.scrollify.enable();
}else{
$.scrollify.disable();
}
});
</script>
解决方案
在您的代码中,无论是否找到.hwdp
该类,都会在每个页面上初始化插件。最好只在需要时才进行初始化。
section
以下是仅当页面上存在带有 class时才启用插件的方法.hwdp
。
<script>
jQuery(document).ready(function($) {
if($('section.hwdp').length) {
$.scrollify({
section : ".hwdp",
interstitialSection: ".footer",
easing: "easeOutExpo",
scrollSpeed: 1200,
offset: 1,
scrollbars: true,
standardScrollElements: "",
setHeights: true,
overflowScroll: true,
updateHash: true,
touchScroll: false,
before:function() {},
after:function() {},
afterResize:function() {},
afterRender:function() {},
});
}
});
</script>
推荐阅读
- jpa - 集成测试,比较 JPA 实体
- hazelcast - 添加新集群节点时删除 Hazelcast Map 中的成员
- javascript - BotFramework-WebChat 用占位符替换聊天头像
- ruby-on-rails - 嵌套表单中不允许的参数嵌套表单
- android - 仅实现 TabLayout 而不是完全支持:Android gradle 中的设计
- android - 什么工具可以更好地创建带有数据库、按钮、表单的移动应用程序
- ruby - Ruby:在 Sinatra 中显示 SNMP 输出
- rust - 发送到数组中的每个 futures::sync::mpsc::Sender
- python - 想要在 python 中执行分组,分组数据将进入行
- java - Maven - 我是否应该包含我导入的库包含的依赖项