File: /www/wwwroot/www.sceybwg.com/wp-content/themes/Modular/static/js/theme-main-1.7.7.js
jQuery(function($){
if(window.location.protocol == 'https:'){
ajaxurl = ajaxurl.replace('http://', 'https://');
}
$.fn.extend({
wpjam_submit: function(callback){
let _this = $(this);
let data = new FormData(_this[0]);
data.append('_ajax_nonce', $(this).data('nonce'));
data.append('action', $(this).data('action'));
data.append('defaults', $(this).data('data'));
data.append('data', $(this).serialize());
$.ajax({
type: 'POST',
url: ajaxurl,
data: data,
processData: false,
contentType: false,
success: function(data){
callback.call(_this, data);
}
});
},
wpjam_action: function(callback){
let _this = $(this);
$.post(ajaxurl, {
_ajax_nonce: $(this).data('nonce'),
action: $(this).data('action'),
data: $(this).data('data')
},function(data, status){
callback.call(_this, data);
});
}
});
$('body').on('click', '.post-action', function(e){
e.preventDefault();
$(this).wpjam_action(function(data){
if(data.errcode != 0){
alert(data.errmsg);
}else{
$(this).removeClass().addClass(data.class).data('data', data.data);
$(this).find('i').removeClass().addClass(data.icon);
$(this).find('span.post-action-count').html(data.count);
$('body').trigger('wpjam_post_action_success', data);
}
});
});
$('body').on('click', '.comment-digg', function(e){
e.preventDefault();
$(this).wpjam_action(function(data){
if(data.errcode != 0){
alert(data.errmsg);
}else{
$(this).removeClass().addClass(data.class).data('data', data.data);
$(this).find('.comment-digg-count').html(data.count);
$(this).find('i').removeClass().addClass(data.icon);
}
});
});
$('.wpjam-form').each(function() {
$(this).on('submit', function(e){
e.preventDefault();
var form = $(this);
// 查找提交按钮
var submitButton = form.find('button[type="submit"]');
// 提交时修改按钮文本和添加class “submitting”
submitButton.addClass("submitting");
$(this).wpjam_submit(function(data){
if(data.errcode){
swal({
title: "Error",
text: data.errmsg,
type: "error",
timer: 3000,
showConfirmButton: false
});
}else{
form[0].reset(); // 清除表单内容
if(data.redirect){
window.location.href = data.redirect;
}else{
swal({
title: data.msg,
//text: '3秒后自动关闭',
type: "success",
timer: 3000,
showConfirmButton: false
});
}
}
// 移除class “submitting”
submitButton.removeClass("submitting");
});
});
});
$('#toc .toc-controller').on('click',function(){
if($(this).hasClass('toc-controller-show')){
$(this).addClass('toc-controller-hide').removeClass('toc-controller-show');
$(this).html('[显示]');
}else{
$(this).addClass('toc-controller-show').removeClass('toc-controller-hide');
$(this).html('[隐藏]');
}
$('#toc ul').toggle();
});
});
(function($) {
/*-------------------------------------------
WOW
-------------------------------------------*/
if (typeof WOW !== 'undefined') {
new WOW({
mobile: false
}).init();
}
/*-------------------------------------------
Fancybox
-------------------------------------------*/
Fancybox.bind('[data-fancybox]', {
//缩略图
Thumbs: {
//新版缩略图
//type: "modern",
//经典缩略图
type: "classic",
},
Images: {
//图片保护,禁止鼠标右键下载图片
protected: true,
},
//工具栏
Toolbar: {
display: {
left: [
"infobar"
],
middle: [
"zoomIn",
"zoomOut",
//"toggle1to1",
"rotateCCW",
"rotateCW",
"flipX",
"flipY",
],
right: [
"slideshow",
"thumbs",
"close"
],
},
},
});
/* -------------------------------------------------------------------------- */
/* 页面滚动给header-menu添加active
/* -------------------------------------------------------------------------- */
var $headerMain = $(".header-style-1, .header-style-2, .header-style-3");
// 如果找到具有这些样式的元素,则定义滚动处理函数
if ($headerMain.length) {
var headerScroll = function () {
var scroll = $(window).scrollTop();
$headerMain.toggleClass("active", scroll > 100);
};
// 初始化时调用一次
headerScroll();
// 滚动事件绑定
$(window).scroll(function () {
headerScroll();
});
}
/* -------------------------------------------------------------------------- */
/* 手机端菜单
/* -------------------------------------------------------------------------- */
$('.hamburger').on('click', function(event) {
// 切换body的fixed定位
if ($('body').css('position') === 'fixed') {
$('body').css('position', '');
} else {
$('body').css('position', 'fixed');
}
// 切换汉堡菜单的活动状态
$(this).toggleClass('h-active');
// 切换菜单的滑动状态
$('.header-menu').toggleClass('slidenav');
// 切换箭头图标
$('.ri-arrow-down-s-line').each(function() {
$(this)
.toggleClass('ri-arrow-down-s-line')
.toggleClass('ri-arrow-right-s-line');
});
});
$(".header-menu .icon-drop-down").on('click', function(event) {
event.preventDefault();
event.stopPropagation();
var $icon = $(this);
var $li = $icon.closest("li.menu-item-has-children");
var $submenu = $li.children(".sub-menu");
// 关闭其他兄弟的子菜单
$li.siblings().find('.sub-menu').slideUp();
$li.siblings().find('.icon-drop-down')
.removeClass('ri-arrow-down-s-line')
.addClass('ri-arrow-right-s-line');
// 切换当前图标
$icon.toggleClass('ri-arrow-down-s-line ri-arrow-right-s-line');
// 展开/折叠当前子菜单
$submenu.slideToggle();
});
/*-------------------------------------------
一键复制按钮
-------------------------------------------*/
$(".copy-btn").each(function(){
var dataOpt = $(this).data('settings');
if (dataOpt) {
var clipboard = new Clipboard('#'+dataOpt.id);
clipboard.on('success', function(e) {
if( dataOpt.copy_tip ){
alert(dataOpt.copy_tip,1500);
}else{
alert('【'+dataOpt.copy+'】复制成功',1500);
}
if( dataOpt.open_wechat ){
window.location.href='weixin://';
}
//e.clearSelection();
//console.log(e.clearSelection);
});
}
});
/*-------------------------------------------
首页幻灯片/滑块
-------------------------------------------*/
document.querySelectorAll('.swiper-banner').forEach(function (container) {
const slides = container.querySelectorAll('.swiper-slide');
const hasMultiple = slides.length > 1;
const swiper = new Swiper(container, {
loop: hasMultiple, // 只有多个才 loop
autoHeight: true,
autoplay: hasMultiple ? {
delay: 3000,
disableOnInteraction: false,
} : false,
navigation: hasMultiple ? {
prevEl: container.querySelector('.swiper-button-prev'),
nextEl: container.querySelector('.swiper-button-next'),
} : false,
pagination: hasMultiple ? {
el: container.querySelector('.swiper-pagination'),
clickable: true,
} : false,
on: {
init() {
handleVideo(this);
},
slideChange() {
handleVideo(this);
}
}
});
});
function handleVideo(swiper) {
var currentSlide = swiper.slides[swiper.activeIndex];
var video = currentSlide.querySelector('video');
if (video) {
// 如果当前幻灯片有视频,暂停 Swiper 的自动切换
swiper.autoplay.stop();
// 确保只绑定一次事件
video.removeEventListener('ended', handleVideoEnded); // 先移除旧的事件
video.addEventListener('ended', handleVideoEnded);
// 开始播放视频
video.play();
// 定义视频结束的回调函数
function handleVideoEnded() {
// 视频播放结束后切换到下一张幻灯片
swiper.slideNext();
// 如果下一张幻灯片也有视频,自动播放
var nextSlide = swiper.slides[swiper.activeIndex];
var nextVideo = nextSlide.querySelector('video');
if (nextVideo) {
nextVideo.play();
}
}
} else {
// 如果当前幻灯片没有视频,恢复 Swiper 的自动切换
swiper.autoplay.start();
}
}
/*-------------------------------------------
首页TAB切换 文章模块
-------------------------------------------*/
function tabsSwiper(menu, con, allowTouchMove) {
var swiper = new Swiper(con, {
speed: 500,
spaceBetween: 10,
autoHeight: true,
allowTouchMove: !allowTouchMove,
on: {
slideChangeTransitionStart: function () {
$(menu).find('li').eq(this.activeIndex).addClass('active').siblings().removeClass('active');
}
}
});
$(menu).find('li').eq(0).addClass('active');
$(menu).on('click', 'li', function (e) {
$(this).addClass('active').siblings().removeClass('active');
swiper.slideTo($(this).index());
});
}
$(".tab-post-menu").each(function(){
var dataOpt = $(this).data('settings');
if (dataOpt) {
tabsSwiper('.menu-'+dataOpt.id, '.content-'+dataOpt.id);
}
});
// 菜单跟随
if ($('.tab-menu-left').length > 0 && typeof $.fn.theiaStickySidebar !== 'undefined') {
$('.tab-menu-left').theiaStickySidebar({
additionalMarginTop: 75
});
}
/*-------------------------------------------
案例展示
-------------------------------------------*/
var swiper = new Swiper('.md-case', {
autoplay: {
delay: 3000,
disableOnInteraction: false, //如果设置为false,用户操作swiper之后自动切换不会停止,每次都会重新启动autoplay。
},
//slidesPerView: 4,
//spaceBetween: 20,
//slidesPerGroup: 4,
loop: true,
loopFillGroupWithBlank: true,
breakpoints: {
768: {
slidesPerView: 1,
slidesPerGroup: 1,
spaceBetween: 15,
},
1020: {
slidesPerView: 4,
slidesPerGroup: 4,
spaceBetween: 20,
},
},
pagination: {
el: '.module-theme-case .swiper-pagination',
clickable: true,
},
navigation: {
nextEl: '.module-theme-case .swiper-button-next',
prevEl: '.module-theme-case .swiper-button-prev',
},
});
/*-------------------------------------------
荣誉资质
-------------------------------------------*/
var swiper = new Swiper(".aptitude-list", {
loop: true,
autoplay: {
delay: 3000,
disableOnInteraction: false, //如果设置为false,用户操作swiper之后自动切换不会停止,每次都会重新启动autoplay。
},
//slidesPerGroup: 4,
//slidesPerView: 4,
//spaceBetween: 20,
pagination: {
el: ".aptitude-list .swiper-pagination",
clickable: true,
},
breakpoints: {
"@0.00": {
slidesPerView: 2,
spaceBetween: 16,
},
"@0.75": {
slidesPerView: 2,
spaceBetween: 16,
},
"@1.00": {
slidesPerView: 2,
spaceBetween: 16,
},
"@1.50": {
slidesPerView: 4,
spaceBetween: 20,
},
},
});
/*-------------------------------------------
产品侧栏菜单
-------------------------------------------*/
$(document).on('click', '.widget_nav_menu .icon-drop-down', function(e) {
e.preventDefault();
e.stopPropagation();
var $icon = $(this);
var $li = $icon.closest('.menu-item-has-children');
var $subMenu = $li.children('.sub-menu');
if (!$li.length) return;
// 判断当前是否处于展开状态(真实状态)
var isOpen = $subMenu.is(':visible');
// ───────────────────────────────────────
// 1. 如果当前是展开 → 折叠整个分支
// ───────────────────────────────────────
if (isOpen) {
// 折叠当前子菜单
$subMenu.stop(true, true).slideUp();
// 关闭所有子孙菜单并加 menu-close
$li.find('.menu-item-has-children').each(function() {
var $childLi = $(this);
$childLi.children('.sub-menu').stop(true, true).slideUp();
$childLi.removeClass('menu-open').addClass('menu-close');
});
// 当前从 open → close
$li.removeClass('menu-open').addClass('menu-close');
return;
}
// ───────────────────────────────────────
// 2. 展开当前菜单逻辑
// ───────────────────────────────────────
// 关闭所有同级菜单
$li.siblings('.menu-item-has-children').each(function() {
var $s = $(this);
// 收起同级 submenu
$s.children('.sub-menu').stop(true, true).slideUp();
// 给同级菜单及其所有子菜单加 menu-close
$s.find('.menu-item-has-children').addBack().each(function() {
$(this).removeClass('menu-open').addClass('menu-close');
});
});
// 展开当前菜单
$subMenu.stop(true, true).slideDown();
// 当前变为 open
$li.removeClass('menu-close').addClass('menu-open');
});
/*-------------------------------------------
产品页面TAB切换菜单
-------------------------------------------*/
//点击切换栏目
// 监听 li 标签的点击事件
$('.product-tab-menu ul li').click(function() {
// 移除所有 li 的 active 类
$('.product-tab-menu ul li').removeClass('active');
// 添加当前点击的 li 的 active 类
$(this).addClass('active');
// 获取当前点击的 li 的 data-tab 属性值
var tabId = $(this).data('tab');
// 隐藏所有 productTab-content
$('.productTab-content').removeClass('active');
// 显示对应的 productTab-content
$('#' + tabId).addClass('active');
// 滚动到相应的 tab-content 区域的顶部
var tabContentTop = $('#' + tabId).offset().top - 135;
$('html, body').animate({scrollTop: tabContentTop}, 'slow');
});
//菜单置顶显示
//获取目标元素的位置
$(document).ready(function() {
//if ($(window).width() > 768) {
var tabMenu = $('.product-tab-menu');
if (tabMenu.length > 0) {
var tabMenuPosition = tabMenu.offset().top;
var postBodyBottom;
// 点击事件处理程序 重新计算 postBodyBottom 的值
$('.product-tab-menu ul li').on('click', function() {
var postBody = $('.productTab-content.active');
postBodyBottom = postBody.offset().top + postBody.outerHeight() - 150;
// 判断是否超出 .post-body 位置
checkPosition();
});
// 初始化时计算 postBodyBottom 的值
$(window).on('load', function() {
var postBody = $('.productTab-content.active');
postBodyBottom = postBody.offset().top + postBody.outerHeight() - 150;
// 判断是否超出 .post-body 位置
checkPosition();
});
// 监听滚动事件
$(window).scroll(function() {
// 获取当前滚动位置
var scrollPosition = $(window).scrollTop();
// 判断是否滚动到.product-tab-menu位置
if (scrollPosition > tabMenuPosition) {
tabMenu.addClass('active');
tabMenu.css('opacity', 1);
} else {
tabMenu.removeClass('active');
}
// 判断是否超出 .post-body 位置
checkPosition();
});
// 检查滚动位置是否超出 .post-body 位置
function checkPosition() {
if (postBodyBottom) {
var scrollPosition = $(window).scrollTop();
if (scrollPosition >= postBodyBottom) {
tabMenu.css('opacity', 0);
} else {
tabMenu.css('opacity', 1);
}
}
}
}
//}
});
/*-------------------------------------------
侧栏跟随
-------------------------------------------*/
$(window).on('load', function() {
// 初始化 StickySidebar
function safeSticky(selector) {
if ($(selector).length > 0 && typeof $.fn.theiaStickySidebar !== 'undefined') {
$(selector).theiaStickySidebar({
additionalMarginTop: 87
});
}
}
// 需要 stick 的元素
safeSticky('.sidebar-widget, .page-main');
safeSticky('.team-single .team-img');
});
/*-------------------------------------------
常见问题列表 手风琴
-------------------------------------------*/
$('.accordion-title').click(function() {
$(this).parent('.post-accordion').toggleClass('active');
$(this).next('.accordion-desc').slideToggle(300);
});
/*-------------------------------------------
如果有提示信息 页面加载完成后自动显示弹窗
-------------------------------------------*/
//$('.license-valid').trigger('click');
/*-------------------------------------------
返回顶部
-------------------------------------------*/
$(window).on('scroll', function () {
if ($(this).scrollTop() > 200) {
$('.scrollup').fadeIn();
} else {
$('.scrollup').fadeOut();
}
});
$('.scrollup').on('click', function () {
$("html, body").animate({
scrollTop: 0
}, 1000);
return false;
});
/*-------------------------------------------
服务项目
-------------------------------------------*/
$('.module-theme-service').each(function() {
var moduleId = $(this).attr("id");
//$(this).find("li").eq(0).addClass("active");
$(this).find(".service-list li").eq(0).addClass("active");
setTimeout(function(){
//accordionFn(".service-list li");
accordionFn("#" + moduleId + " .service-list li");
function accordionFn(el){
if(window.innerWidth >= 1151){
var accordionStart = $(el+":last")[0].offsetWidth;
var accordionEnd = $(el+".active")[0].offsetWidth;
$(el).mouseenter(function (){
if(!$(this).hasClass("active")){
$(this).stop().animate({width: accordionEnd},400).siblings().stop().animate({width: accordionStart},400);
$(this).addClass("active").siblings().removeClass("active");
}
});
};
};
},500);
});
/*-------------------------------------------
自定义TAB
-------------------------------------------*/
$('.module-theme-tab').each(function () {
const $module = $(this);
const $tabs = $module.find('.module-tab-menu ul li');
const $items = $module.find('.module-tab-box > .tab-item');
$tabs.on('click', function () {
const index = $(this).index();
// tab 高亮
$(this)
.addClass('selected')
.siblings()
.removeClass('selected');
// 内容切换
$items
.eq(index).show()
.siblings('.tab-item').hide();
// 图片状态
$items.find('.tab-img-item').removeClass('adclass');
$items.eq(index).find('.tab-img-item').addClass('adclass');
});
});
/*-------------------------------------------
文章分享
-------------------------------------------*/
$(document).ready(function() {
var $postShare = $(".post-share");
// 如果找到具有这些样式的元素,则定义滚动处理函数
if ($postShare.length) {
$('body').on('click', '.post-share-item:not(".prevent-share-popup")', function(e) {
e.preventDefault();
post_share_popup($(this).attr('data-url'));
});
$('#sharer-wechat').qrcode({
text : $('#sharer-wechat').attr('data-url')
});
}
});
function post_share_popup(data) {
window.open(data, "Share", 'height=500,width=760,top=' + ($(window).height() / 2 - 250) + ', left=' + ($(window).width() / 2 - 380) + 'resizable=0,toolbar=0,menubar=0,status=0,location=0,scrollbars=0');
}
/*-------------------------------------------
swiper 时间轴
-------------------------------------------*/
if ($('.theme-history2').length > 0) {
$('.theme-history2').each(function () {
var dataOpt = $(this).data('settings');
// 为每个 swiper 模块初始化 swiperDate 和 swiperMain
var swiperDate = new Swiper( '.theme-history-'+dataOpt.id+' .history-swiper-date', {
spaceBetween: 5, //间距
slidesPerView: 3,
freeMode: true,
watchSlidesProgress: true,
// allowTouchMove: false, // 禁止通过拖动滑动
speed: 0, // 关闭动画
breakpoints: {
768: { // PC 端配置 (宽度 >= 768px)
slidesPerView: 7,
}
}
});
var swiperMain = new Swiper( '.theme-history-'+dataOpt.id+' .history-swiper', {
spaceBetween: 10, //间距
autoHeight: true, // 高度自适应
thumbs: {
swiper: swiperDate,
},
navigation: {
nextEl: '.theme-history-'+dataOpt.id+' .history-next',
prevEl: '.theme-history-'+dataOpt.id+' .history-prev',
},
breakpoints: {
768: {
autoHeight: false, // 高度自适应
}
}
});
// 统一逻辑处理函数
function handleThumbScroll() {
var activeIndex = swiperMain.activeIndex;
var slidesPerView = swiperDate.params.slidesPerView;
// 如果是最后一个可视项目
if (activeIndex >= swiperDate.activeIndex + slidesPerView - 1) {
swiperDate.slideTo(swiperDate.activeIndex + 1); // 向后滚动一个项目
}
// 如果是第一个可视项目
if (activeIndex <= swiperDate.activeIndex && swiperDate.activeIndex > 0) {
swiperDate.slideTo(swiperDate.activeIndex - 1); // 向前滚动一个项目
}
}
// 监听主轮播的 slide 切换事件(包括拖动和点击切换)
swiperMain.on('slideChange', function () {
handleThumbScroll();
});
// 监听 thumb 滑块的点击事件
swiperDate.on('click', function (swiper) {
handleThumbScroll();
});
// 监听 navigation 按钮的点击事件
$('.theme-history-'+dataOpt.id+' .history-next').on('click', function () {
handleThumbScroll();
});
$('.theme-history-'+dataOpt.id+' .history-prev').on('click', function () {
handleThumbScroll();
});
});
}
/*-------------------------------------------
视频模块
-------------------------------------------*/
function handleScroll() {
$(".module-theme-video").each(function (index) {
let $triggerElement = $(this);
let $targetElement = $(".video-transition").eq(index);
if ($targetElement.length === 0) return;
let triggerTop = $triggerElement[0].getBoundingClientRect().top;
let triggerHeight = $triggerElement.outerHeight();
let windowHeight = $(window).height();
// 触发点:只有当 .module-theme-video 完全进入视口(顶部到窗口底部之间)时才开始动画
if (triggerTop < windowHeight && triggerTop > -triggerHeight) {
// 计算滚动比例,使其在完全进入视口时开始动画
let scrollRatio = Math.min(Math.max((windowHeight - triggerTop) / (windowHeight + triggerHeight), 0), 1);
$targetElement.css({
transform: `translateY(${80 * (1 - scrollRatio)}px) scale(${0.8 + 0.2 * scrollRatio})`,
opacity: scrollRatio
});
}
});
}
$(window).on("scroll", handleScroll);
handleScroll();
})(jQuery);