I've been trying to add my custom jQuery script to wordpress, the script code and all is working on jsfiddle when I choose the jquery library, but when I'm trying to add it on wordpress it is not working. Here's how added the wp enqueue code:
我一直在尝试将我的自定义jQuery脚本添加到wordpress,脚本代码,当我选择jquery库时,所有人都在使用jsfiddle,但是当我尝试在wordpress上添加它时,它无效。这是添加wp入队代码的方法:
function cb_scroller() {
//wp_enqueue_script('jquery');
wp_register_script( 'scroller', get_template_directory_uri() . '/js/scroller.js', array('jquery'),'',true );
wp_enqueue_script( 'scroller' );
}
add_action( 'wp_enqueue_scripts', 'cb_scroller' );
So what may be the problem? here's the jsfiddle attempt: https://jsfiddle.net/naimelhajj/q4bdfcwb/ (disregard the styling, I've imported the css and js as "external resources")
那可能是什么问题呢?这里是jsfiddle尝试:https://jsfiddle.net/naimelhajj/q4bdfcwb/(忽略样式,我已将css和js导入为“外部资源”)
1 个解决方案
#1
2
This is your script (which you should have posted in the question)
这是你的脚本(你应该在问题中发布)
$(document).ready(function(){
$(".arrow-left").click(function(){
$(".site-main-gluten").animate({scrollLeft: "-="+100});
});
$(".arrow-right").click(function(){
$(".site-main-gluten").animate({scrollLeft: "+="+100});
});
});
Wordpress is in no-conflict mode by default, which means $
is not defined, it has to be
默认情况下,Wordpress处于非冲突模式,这意味着$未定义,必须是
jQuery(document).ready(function($){
$(".arrow-left").click(function(){
$(".site-main-gluten").animate({scrollLeft: "-="+100});
});
$(".arrow-right").click(function(){
$(".site-main-gluten").animate({scrollLeft: "+="+100});
});
});
#1
2
This is your script (which you should have posted in the question)
这是你的脚本(你应该在问题中发布)
$(document).ready(function(){
$(".arrow-left").click(function(){
$(".site-main-gluten").animate({scrollLeft: "-="+100});
});
$(".arrow-right").click(function(){
$(".site-main-gluten").animate({scrollLeft: "+="+100});
});
});
Wordpress is in no-conflict mode by default, which means $
is not defined, it has to be
默认情况下,Wordpress处于非冲突模式,这意味着$未定义,必须是
jQuery(document).ready(function($){
$(".arrow-left").click(function(){
$(".site-main-gluten").animate({scrollLeft: "-="+100});
});
$(".arrow-right").click(function(){
$(".site-main-gluten").animate({scrollLeft: "+="+100});
});
});