即使其他加载的 jQuery 函数正在运行,自定义 jQuery 函数也无法在 WordPress 上运行 [英] Custom jQuery-function not working on WordPress even though other loaded jQuery functions are working
本文介绍了即使其他加载的 jQuery 函数正在运行,自定义 jQuery 函数也无法在 WordPress 上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是 WordPress 3.8.1.我想用这个函数来使用sticky header
I'm using WordPress 3.8.1. I want to use this function to use sticky header
<script>
$(document).ready(function() {
var $header = $("header"),
$clone = $header.before($header.clone().addClass("clone"));
$(window).on("scroll", function() {
var fromTop = $(window).scrollTop();
console.log(fromTop);
$("body").toggleClass("down", (fromTop > 200));
});
});
</script>
但这对我不起作用,我不知道为什么.我知道 jQuery 已共享给我的 WordPress,因为 Flexslider 2 现在工作正常.
But it is not working for me and I don't know why. I know that jQuery is shared to my WordPress because Flexslider 2 is now working fine.
推荐答案
添加:
var j = jQuery.noConflict();
现在您可以像这样编写 jQuery 代码:
Now you can write your jQuery code like this:
j(document).ready(function(){
j('.class').event(function(){
// your action............
});
});
只需将 noConflict()
函数分配给一个变量,并使用该变量代替 jQuery 代码中看到的 $
.
Just assign the noConflict()
function to a variable, and use that variable instead of $
seen in jQuery code.
这篇关于即使其他加载的 jQuery 函数正在运行,自定义 jQuery 函数也无法在 WordPress 上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文