嗨,我的java脚本代码在我的wordpress
主题我将我的scripts.js
文件问题是什么,预期的行为是什么?
function my_scripts() {
wp_enqueue_style( \'responsive\', get_template_directory_uri() .\'/assets/css/responsive.css\' , array() );
wp_enqueue_script( \'scripts\', get_template_directory_uri() . \'/assets/js/scripts.js\', array(), true );
}
add_action( \'wp_enqueue_scripts\', \'my_scripts\' );
scripts.js
文件:
jQuery(document).ready(function($){
/*------ Masonry ------*/
$(".post-four.grid .row").masonry({
itemSelector: ".post",
horizontalOrder: true
});
/*------ Search button ------*/
let hasFocus = false;
$(".header-top .header-search .searchform i").click(function() {
const setState = hasFocus ? \'blur\' : \'focus\';
$(\'.header-top .header-search .searchform #s\')[setState]();
hasFocus = !hasFocus;
});
let hasFocusTwo = false;
$(".header-sticky-inner .header-search i").click(function() {
const setStateTwo = hasFocusTwo ? \'blur\' : \'focus\';
$(\'.header-sticky-inner .header-search #input-search\')[setStateTwo]();
hasFocusTwo = !hasFocusTwo;
});
/*------ Sidebar ------*/
$(".sidebar-button #sidebarButton").click(function(){
$("body").addClass("sidebar-active");
});
$(".sidebar-right #closebtn").click(function(){
$("body").removeClass("sidebar-active");
});
$("#content-bg").click(function(){
$("body").removeClass("sidebar-active");
});
$(".sidebar-button-menu #sidebarButton").click(function(){
$("body").addClass("sidebar-active-menu");
});
$(".sidebar-menu #closebtn").click(function(){
$("body").removeClass("sidebar-active-menu");
});
$("#content-bg").click(function(){
$("body").removeClass("sidebar-active-menu");
});
/*------ Drop Down Menu ------*/
let dropdown = $(".has-child a");
let i;
for (i = 0; i < dropdown.length; i++) {
dropdown[i].addEventListener("click", function() {
this.classList.toggle("active");
let dropdownContent = this.nextElementSibling;
if (dropdownContent.style.display === "block") {
dropdownContent.style.display = "none";
} else {
dropdownContent.style.display = "block";
}
});
}
/*------ Grid Tab ------*/
$(\'.grid-tab > li > a\').on(\'click\', function(e) {
e.preventDefault();
$(this).closest(\'.grid-tab > li\').toggleClass(\'active-li\')
.siblings(\'.grid-tab > li\').removeClass(\'active-li\');
});
/*------ Scroll ------*/
let previousScroll = 0;
let memoScroll = $("header").height() - $(".header-sticky").height();
$(window).scroll(function(event){
let scrolled = $(window).scrollTop();
if (scrolled > memoScroll){
if (scrolled < previousScroll){
$(".header-sticky").addClass("visible");
} else {
$(".header-sticky").removeClass("visible");
}
}else {
$(".header-sticky").removeClass("visible");
}
previousScroll = scrolled;
});
});
/*------ OWL Carousel ------*/
$(".owl-instagram, .owl-category, .owl-post-wg").owlCarousel({
items:1,
dots:true
});
$(".sidebar-right .owl-instagram,.sidebar-right .owl-category,.sidebar-right .owl-post-wg").owlCarousel({
items:1,
dots:true
});
$(".owl-instagram-feed").owlCarousel({
items:5,
dots:false,
nav: true,
navText: [\'<i class="ion-android-arrow-back"></i>\',\'<i class="ion-android-arrow-forward"></i>\'],
loop: true,
responsiveClass: true,
responsive: {
0:{
items:2
},
576:{
items:3
},
768:{
items:4
},
992:{
}
}
});
$(".owl-slider").owlCarousel({
items: 1,
loop: true,
nav: true,
navText: [\'<i class="ion-android-arrow-back"></i>\',\'<i class="ion-android-arrow-forward"></i>\'],
dots: true,
mouseDrag: false
});
$(".owl-slider-center").owlCarousel({
items: 2,
center: true,
margin: 10,
loop: true,
nav: true,
navText: [\'<i class="ion-android-arrow-back"></i>\',\'<i class="ion-android-arrow-forward"></i>\'],
dots: false,
mouseDrag: true,
removeClass: true,
responsive:{
0:{
center:false,
items:1
},
576:{
items:1,
center:false
},
768:{
items:1,
center:false
},
992:{
}
}
});