/** * WP2020 * Custom Javascript */ jQuery(document).ready(function () { "use strict"; /** * 顶部导航栏固定 */ jQuery(window).bind("scroll", function () { // console.log("scrollTop:" + jQuery(this).scrollTop()); let bodyWidth = document.body.clientWidth; let navbar = jQuery("body").find(".navbar"); let navbarHeight = jQuery(".navbar").height(); if (jQuery(this).scrollTop() > navbarHeight && bodyWidth > 0) { navbar.addClass("menu-fixed fixed-top"); jQuery("#site-content").css({ "padding-top":navbarHeight }); } else { navbar.removeClass("menu-fixed fixed-top"); jQuery("#site-content").css({ "padding-top":0 }); } }); /** * Anchor * 预设的锚点以及动画,可以在链接上带上anchor类,即会滚动至对应的href的section位置: */ jQuery(".anchor a, a.anchor").click(function () { if (jQuery('.' + jQuery(this).prop('href').split("#")[1]).offset()) { jQuery('html, body').animate({ scrollTop: jQuery('.' + jQuery(this).prop('href').split("#")[1]).offset().top }, 500); } else if(jQuery('#' + jQuery(this).prop('href').split("#")[1]).offset()){ jQuery('html, body').animate({ scrollTop: jQuery('#' + jQuery(this).prop('href').split("#")[1]).offset().top }, 500); }; }); jQuery(function hashAnchor() { if (window.location.hash) { if (jQuery('.' + window.location.hash.split("#")[1]).offset()) { jQuery('html, body').animate({ scrollTop: jQuery('.' + window.location.hash.split("#")[1]).offset().top }, 500); } else if(jQuery(window.location.hash).offset()){ jQuery('html, body').animate({ scrollTop: jQuery(window.location.hash).offset().top }, 500); } }; }); /** * Back To Top * 点击以后回到顶部 */ jQuery(".back-to-top").click(function (e) { e.preventDefault(); jQuery("html, body").animate({ scrollTop: 0 }, 500); return false }); /** * Swiper Gallery * 相册的轮播 */ var galleryThumbs = new Swiper('.gallery-thumbs', { spaceBetween: 10, slidesPerView: 4, freeMode: true, watchSlidesVisibility: true, watchSlidesProgress: true, }); var galleryTop = new Swiper('.gallery-top', { spaceBetween: 10, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, thumbs: { swiper: galleryThumbs } }); /** * Product Sidebar */ jQuery(".cat_item_has_children").click(function () { jQuery(this).toggleClass('global-menu-show'); jQuery(this).children('.children').toggle(); }); jQuery(".page_item_has_children").click(function () { jQuery(this).toggleClass('global-menu-show'); jQuery(this).children('.children').toggle(); }); /** * GLightbox * Params 'data-glightbox' 'data-gallery' *激活Glightbox */ var lightbox = GLightbox(); /** * Tab * Tab栏的点击切换效果 */ jQuery(".custom-tab-content > .tab-content:first-child").addClass("active-content"); jQuery(".custom-tab-btn > li:first-child").addClass('active-tab'); jQuery(".custom-tab-btn li.tab-btn").click(function () { jQuery(this).addClass("active-tab").siblings().removeClass('active-tab'); jQuery("#" + jQuery(this).data("id")).addClass("active-content").siblings().removeClass('active-content'); }); /** * Menu *用于小屏时点击箭头打开菜单时改变箭头的方向 */ jQuery(".ddl-switch").on("click", function () { var li = jQuery(this).parent(); if (li.hasClass("ddl-active") || li.find(".ddl-active").length !== 0 || li.find(".dropdown-menu").is(":visible")) { li.removeClass("ddl-active"); li.children().find(".ddl-active").removeClass("ddl-active"); li.children(".dropdown-menu").slideUp(); } else { li.addClass("ddl-active"); li.children(".dropdown-menu").slideDown(); } }); jQuery(document).off('click.bs.dropdown.data-api'); }); /** * Menu * 窗口宽度大于991不显示箭头和样式小于991时不显示样式 */ jQuery(window).resize(function () { "use strict"; var width = jQuery(window).width(); if (jQuery(".ownavigation .navbar-nav li.ddl-active").length) { if (width > 991) { jQuery(".ownavigation .navbar-nav > li").removeClass("ddl-active"); jQuery(".ownavigation .navbar-nav li .dropdown-menu").removeAttr("style"); } } else { jQuery(".ownavigation .navbar-nav li .dropdown-menu").removeAttr("style"); } }); /** * Sidebar Fixed Panel *大屏时使左边菜单悬浮,小屏时使菜单不悬浮 */ jQuery(window).load(function () { var navHeight = 90; /* header高度 */ if (jQuery("#contentRight").length > 0 && jQuery("#contentLeft").length > 0) { var contentRightTop = jQuery("#contentRight").offset().top - navHeight, contentRightHeight = jQuery("#contentRight").height(), contentLeftHeight = jQuery("#contentLeft").height(); if (jQuery(window).width() >= 992) { if (contentRightHeight > contentLeftHeight) { jQuery(window).on('scroll', function () { var scrollTop = jQuery(this).scrollTop(); if (scrollTop >= contentRightTop && (scrollTop + contentLeftHeight) <= (contentRightTop + contentRightHeight)) { jQuery("#contentLeft").addClass('fixed-panel'); } else { jQuery("#contentLeft").removeClass('fixed-panel'); } }); } } } }); //Animation动画库,滚动至动画区域并激活 jQuery(document).ready(function() { jQuery(window).on('scroll', function() { var scrollHeight = jQuery(this).scrollTop(); jQuery('.animate__trigger').each(function() { var windowHeight = jQuery(window).height(), sectionsOffest = jQuery(this).offset().top; sectionsTop = sectionsOffest - windowHeight + 200; /* 动画区域位置修正 */ if (scrollHeight >= sectionsTop || scrollHeight >= sectionsOffest) { jQuery(this).addClass('animate_active'); } }); }); }); //瀑布流的循环 jQuery(document).ready(function ($) { let $grid = $("#masonry-list").masonry({ itemSelector: "none", // select none at first columnWidth: ".masonry-item", percentPosition: true, stagger: 30, visibleStyle: { transform: "translateY(0)", opacity: 1 }, hiddenStyle: { transform: "translateY(100px)", opacity: 0 }, }); let msnry = $grid.data("masonry"); $grid.imagesLoaded(function () { $grid.removeClass("are-images-unloaded"); $grid.masonry("option", { itemSelector: ".masonry-item" }); let $items = $grid.find(".masonry-item"); $grid.masonry("appended", $items); }); $grid.infiniteScroll({ path: ".nextpostslink", append: ".masonry-item", outlayer: msnry, history: false, hideNav: ".wp-pagenavi", status: ".page-load-status", }); }); jQuery(document).ready(function() { var windowWidth = jQuery(window).width(); var containerWidth = 1600; var swiperPadding = windowWidth / 2 - containerWidth / 2; if (windowWidth < 992) { jQuery(".section-content-left").css("margin-left", ""); jQuery(".section-content-right").css("margin-right", ""); } else if (windowWidth >= 992) { jQuery(".section-content-left").css({ "margin-left": swiperPadding }); jQuery(".section-content-right").css({ "margin-right": swiperPadding }); }; }); jQuery(window).resize(function() { var windowWidth = jQuery(window).width(); var containerWidth = 1600; var swiperPadding = windowWidth / 2 - containerWidth / 2; if (windowWidth < 992) { jQuery(".section-content-left").css("margin-left", ""); jQuery(".section-content-right").css("margin-right", ""); } else if (windowWidth >= 992) { jQuery(".section-content-left").css({ "margin-left": swiperPadding }); jQuery(".section-content-right").css({ "margin-right": swiperPadding }); }; }); jQuery(document).ready(function() { var windowWidth = jQuery(window).width(); var containerWidth = 1600; var swiperPadding = windowWidth / 2 - containerWidth / 2; if (windowWidth < 992) { jQuery(".section-content-left-broad").css("margin-left", ""); jQuery(".section-content-right-broad").css("margin-right", ""); } else if (windowWidth >= 992) { jQuery(".section-content-left-broad").css({ "margin-left": swiperPadding }); jQuery(".section-content-right-broad").css({ "margin-right": swiperPadding }); }; }); jQuery(window).resize(function() { var windowWidth = jQuery(window).width(); var containerWidth = 1800; var swiperPadding = windowWidth / 2 - containerWidth / 2; if (windowWidth < 992) { jQuery(".section-content-left-broad").css("margin-left", ""); jQuery(".section-content-right-broad").css("margin-right", ""); } else if (windowWidth >= 992) { jQuery(".section-content-left-broad").css({ "margin-left": swiperPadding }); jQuery(".section-content-right-broad").css({ "margin-right": swiperPadding }); }; }); jQuery(document).ready(function() { var windowWidth = jQuery(window).width(); var containerWidth = 1080; var swiperPadding = windowWidth / 2 - containerWidth / 2; if (windowWidth < 992) { jQuery(".section-content-left-xl").css("margin-left", ""); jQuery(".section-content-right-xl").css("margin-right", ""); } else if (windowWidth >= 992) { jQuery(".section-content-left-xl").css({ "margin-left": swiperPadding }); jQuery(".section-content-right-xl").css({ "margin-right": swiperPadding }); }; }); jQuery(window).resize(function() { var windowWidth = jQuery(window).width(); var containerWidth = 1080; var swiperPadding = windowWidth / 2 - containerWidth / 2; if (windowWidth < 992) { jQuery(".section-content-left-xl").css("margin-left", ""); jQuery(".section-content-right-xl").css("margin-right", ""); } else if (windowWidth >= 992) { jQuery(".section-content-left-xl").css({ "margin-left": swiperPadding }); jQuery(".section-content-right-xl").css({ "margin-right": swiperPadding }); }; });