var whirMain = { apple:function(width){ function isMac() { return /Macintosh|MacIntel|MacPPC|Mac68K/.test(navigator.userAgent); } if (isMac()) { $('html').addClass('isMac'); function updateFontSize() { // 获取视口宽度 var viewportWidth = window.innerWidth; if(viewportWidth=1){ $(".header").addClass("fix"); }else{ $(".header").removeClass("fix"); } }); //搜索s $(".top_search .ico").click(function() { $(this).toggleClass("on"); $(this).next().slideToggle(); }); //滑过显示阴影效果 $(".itemhover").hover(function(){ $(this).addClass("activehover"); },function(){ $(this).removeClass("activehover"); }); $(".itemhover2").hover(function(){ $(this).addClass("activehover2"); },function(){ $(this).removeClass("activehover2"); }); //tab $('.TabSlide').each(function () { var _this = $(this); _this.find(".tabCon:first").removeClass("nones").addClass("animated fadeInUpSmall"); _this.find(".tabNav .item").eq(0).addClass("on"); _this.find(".tabNav .item").on("mouseover", function () { var num = $(this).index(); $(this).addClass("on"); $(this).siblings().removeClass("on"); _this.find(".tabCon").addClass("nones").removeClass("animated fadeInUpSmall"); _this.find(".tabCon").eq(num).removeClass("nones").addClass("animated fadeInUpSmall"); }); }); }, menu:function(){ $("menu li").each(function () { var n = $(this).find(".sub").find("dd").length if (n >= 1) { $(this).addClass("has-sub"); $(this).find("span").append(""); $(this).hover(function () { $(this).addClass("active").siblings().removeClass("active"); }, function () { $(this).removeClass("active"); }); } }); $(".wap-op").click(function () { $(this).parents("span").toggleClass("on"); $(this).parent("span").next(".sub").slideToggle(); $(this).parents("li").siblings().find("span").removeClass("on"); $(this).parents("li").siblings().find(".sub").slideUp(); }); }, bottom: function (a,b,c,d) { //搜索功能 whirSearch.one("#TopBtn", "TopKey", a, b, c, d, searchpath) whirSearch.two("#TopBtn2", "TopKey2", a, b, c, d, searchpath2) //截取字符 $("[data-dots]").each(function () { var n = $(this).data("dots") $(this).css("--wlc", n); $(this).addClass("dots-n"); }); //wow引用 if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))) { var wow = new WOW({ boxClass: 'wow', animateClass: 'animated', offset: 0, mobile: false, live: true }); wow.init(); }; //top引用 whirMain.top(); //栏目页banner效果 $(".pageBan").addClass("on"); if ($(".pageBan").length != 0) { $(window).scroll(function () { var scrollTop = $(window).scrollTop(); if ($(".pageBan").length > 0) { $(".pageBan .ispic").css({ "-webkit-transform": "translateY(" + scrollTop * 0.5 + "px)" }) } }); } if ($(".Pages .p_page a").length == 0) { $(".Pages").hide(); } //栏目页二级栏目折叠 if($(".subMenu ul li").length==0){ $(".colName").hide(); }; $(".colName").click(function(){ $(this).toggleClass("on"); $(this).next().slideToggle(); }); //友情链接 $(".selectBox").each(function(){ var _this=$(this); _this.find("dt").click(function(){ $(this).addClass("on").parent().siblings().find("dt").removeClass("on"); $(this).next().slideToggle(); _this.siblings().find("dd").slideUp(); }); }); $(document).bind("click", function(e) { var target = $(e.target); if (target.closest(".selectBox dt").length == 0) { $(".selectBox dd").slideUp(); $(".selectBox dt").removeClass("on"); } }); //详情页 $(".PrevNextInfo dl").each(function() { var myhref = $(this).find("a").attr("href"); if (myhref == "#") { $(this).find("a").addClass("none"); $(this).find("a").removeAttr("href"); } }); $(".singlePage p").each(function() { if ($(this).has("img").length > 0) { $(this).addClass("tc").css("text-indent","0em"); } }) $(window).scroll(function() { if($(window).scrollTop()>=100){ $(".fixNav").addClass("show"); }else{ $(".fixNav").removeClass("show"); } }); //返回顶部 var offset = 200, offset_opacity = 1200, scroll_top_duration = 1000, $back_to_top = $('.totop'); $(window).scroll(function(){ ( $(this).scrollTop() > offset ) ? $back_to_top.addClass('cd-is-visible') : $back_to_top.removeClass('cd-is-visible'); var win_top = $(this).scrollTop(); var _top = $(".footer .blank").offset().top; if (win_top >= _top) { $(".totop").addClass("fix"); } else { $(".totop").removeClass("fix"); } }); $('.totop').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);}); //整站无图处理 $.each($("img"), function (i, n) { $(n).on('error', function () { n.src = nopicpath; }); n.src = n.src; }); }, home:function(){ var newsSwiper = new Swiper('.topNews .swiper-container', { slidesPerView: 1, autoplay: { delay: 4000, }, loop: false, // pagination: { el: '.topNews .swiper-pagination', clickable: true }, }); //news var focusSwiper = new Swiper('.focusNews', { slidesPerView: 1, autoplay: { delay: 4000, }, loop: false, // pagination: { el: '.focusNews .swiper-pagination', clickable: true }, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, }); //news var proSwiper = new Swiper('.home-pro .swiper-container', { slidesPerView: 4, spaceBetween : 50, loop: false, // navigation: { nextEl: '.home-pro .swiper-button-next', prevEl: '.home-pro .swiper-button-prev', }, scrollbar: { el: '.swiper-scrollbar', draggable: true }, on: { init: function() { updatePagination(this); }, slideChange: function() { updatePagination(this); } }, breakpoints: { 1024: {spaceBetween : 30, }, 768: { slidesPerView: 3,spaceBetween : 30, }, 480: { slidesPerView: 2,spaceBetween : 10, }, }, }); // 更新分页显示函数 function updatePagination(swiper) { const current = swiper.activeIndex + 1; const total = swiper.slides.length; document.querySelector('.swiper-info .current').textContent = current.toString().padStart(2, '0'); document.querySelector('.swiper-info .total').textContent = total.toString().padStart(2, '0'); } //pro }, } //搜索插件 var whirSearch = { one: function (btn, kid, txt, txt1, txt2, txt3, url) { $(btn).jqSearch({ TxtVal: txt, KeyTxt1: txt1, KeyTxt2: txt2, KeyTxt3: txt3, KeyId: kid, //输入框id KeyUrl: url, //跳转链接 KeyHref: "key", //链接传值 Static: false //是否静态站 }); }, two: function (btn, kid, txt, txt1, txt2, txt3, url) { $(btn).jqSearch({ TxtVal: txt, KeyTxt1: txt1, KeyTxt2: txt2, KeyTxt3: txt3, KeyId: kid, //输入框id KeyUrl: url, //跳转链接 KeyHref: "key", //链接传值 Static: false //是否静态站 }); } } //打开效果 var whirOpen = { toggle: function (btn, main, css, out) { $(btn).click(function (e) { $(main).toggleClass(css); $(document).on("click", function () { $(main).removeClass(css); }); e.stopPropagation(); }); $(out).on("click", function (e) { e.stopPropagation(); }); }, fade: function (a, b) { $(a).click(function (e) { $(this).toggleClass("on"); $(b).stop(true, true).fadeToggle(); $(document).on("click", function () { $(b).stop(true, true).fadeOut(); $(a).removeClass("on"); }); e.stopPropagation(); }); $(b).on("click", function (e) { e.stopPropagation(); }); }, hover: function (a) { $(a).hover(function () { $(this).addClass("active"); }, function () { $(this).removeClass("active"); }); }, video: function () { //视频弹窗 $(".play").click(function (e) { var files = $(this).data("files"); $(".video-box").remove(); $('body').append("
"); $('body').css("overflow", "hidden"); videoclose(); }); function videoclose() { $(".video-box .close").click(function (e) { $(".video-box").remove(); $('body').css("overflow", "auto"); }); } } } var swiperVideo; var whirRootVideo = { /** * 初始化视频轮播 * @param {string} name - 轮播容器选择器 * @param {array} arr - 轮播图片数组 * @param {string} ef - 轮播切换效果,默认为 'fade' * @param {string} pt - 分页器类型,默认为 'bullets' * @returns {void} */ banner: function (name, arr, ef, pt) { // 确保 arr 是数组 arr = Array.isArray(arr) ? arr : []; // 定义默认选择器 var defaultSelectors = [ '.swiper-video', '.swiper-slide', '.controls-page', '.total', '.cur', '.next', '.prev' ]; // 合并默认选择器和用户提供的选择器 var newArr = []; for (var i = 0; i < defaultSelectors.length; i++) { // 如果用户提供了选择器且不为null,则使用用户的选择器,否则使用默认选择器 newArr.push(name + " " + (arr[i] || defaultSelectors[i])); } let num_total = $(newArr[1]).length let num_total_real = num_total <=9?'0'+num_total:num_total $(newArr[3]).text(num_total_real); whirRootVideo.addVideo(newArr[1]); whirRootVideo.main(newArr[0], ef, newArr[2], pt, newArr[5], newArr[6]); swiperVideo.on('slideChange', function () { var index = swiperVideo.realIndex; var num= index + 1 var num_real = num <=9?'0'+num :num; $(newArr[4]).text(num_real); }) }, /** * 配置并初始化 Swiper 视频轮播 * @param {string} m - 轮播容器选择器 * @param {string} meffect - 轮播切换效果,默认为 'fade' * @param {string} page - 分页器选择器 * @param {string} pagetype - 分页器类型,默认为 'bullets' * @param {string} btnN - 下一个按钮选择器 * @param {string} btnP - 上一个按钮选择器 * @returns {void} */ main: function (m, meffect, page, pagetype, btnN, btnP) { swiperVideo = new Swiper(m, { loop: true, speed: 1500, autoplay: { delay: 6500, disableOnInteraction: false }, effect: meffect ? meffect : 'fade', fadeEffect: { crossFade: true, }, pagination: { el: page, type: pagetype ? pagetype : 'bullets', clickable: true, formatFractionCurrent: function (number) { return number < 10 ? '0' + number : number; }, formatFractionTotal: function (number) { return number < 10 ? '0' + number : number; } }, navigation: { nextEl: btnN, prevEl: btnP, }, on: { init: function () { for (let index = 0; index < this.slides.length; index++) { const element = this.slides[index]; if ($(element).find('video').length > 0) { $(element).find('video').attr("id", "banner-video__" + index) } } playVideo(this.slides, this.activeIndex); }, slideChange: function () { for (let index = 0; index < this.slides.length; index++) { const element = this.slides[index]; if ($(element).find('video').length > 0) { $(element).find('video')[0].pause(); $(element).find('video')[0].currentTime = 0; $(element).find('video')[0].muted = true; $(element).find('.video-inner').removeClass("active"); } } playVideo(this.slides, this.activeIndex); } } }); function playVideo(slide, index) { var videoInner = $(slide[index]).find('.video-inner'); var winW = $(window).width() || window.innerWidth; var t = setTimeout(function () { if (videoInner.length > 0) { if (winW <= 768) {//WAP // 移除之前可能存在的事件监听器,防止重复绑定 videoInner.find(".open-video").off('click').on("click", function () { if (swiperVideo && swiperVideo.autoplay) { swiperVideo.autoplay.stop(); } videoInner.addClass("active"); // 使用jQuery查找视频元素,避免getElementById可能的null问题 var videoElement = videoInner.find("video")[0]; if (videoElement) { videoElement.play(); videoElement.muted = false; // 移除之前可能存在的ended事件监听器 $(videoElement).off('ended').on('ended', function() { swiperVideo.slideNext(); swiperVideo.autoplay.start(); videoInner.removeClass("active"); }); } }); } else {//PC if (swiperVideo && swiperVideo.autoplay) { swiperVideo.autoplay.stop(); } // 使用jQuery查找视频元素,避免getElementById可能的null问题 var videoElement = videoInner.find("video")[0]; if (videoElement) { videoElement.play(); // 移除之前可能存在的ended事件监听器 $(videoElement).off('ended').on('ended', function() { swiperVideo.slideNext(); swiperVideo.autoplay.start(); }); } } } clearTimeout(t); }, 100); } }, /** * 为轮播项添加视频元素 * @param {string} m - 轮播项选择器 * @returns {void} */ addVideo: function (m) { $(m).each(function (e) { var videoInner = $(this).find(".video-inner"); if (videoInner.length > 0) { var _files = ''; var files_desktop = videoInner.data("files_desktop"); var files_mobile = videoInner.data("files_mobile"); if (window.innerWidth > 768) { _files = files_desktop; } else { _files = files_mobile ? files_mobile : files_desktop; } //添加视频 videoInner.append("
"); //添加移动端播放按钮 videoInner.append("
"); } }) } }