即使其他加载的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。我想使用此函数来使用粘性标题
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屋!
查看全文