$(document).ready(function () { $(".headr h3").click(function () { $(this).find("i").toggleClass("up"); $(this).next(".selsubdl").stop(true, false).slideToggle("fast"); }); $(".selsubdl dt").click(function () { $(this).addClass("active").siblings().removeClass("active"); var text = $(this).text(); $(this).parents(".headr").find(".inputsel").val(text); $(this).parents(".headr").find("i").removeClass("up"); $(this).parent(".selsubdl").stop(true, false).slideUp("fast"); }); //轮播图和文字信息 $(".focusBox").slide({ titCell: ".num li", mainCell: ".pic", effect: "left", autoPlay: true, trigger: "click", mouseOverStop: false, vis: "auto", startFun: function (i) { // console.log("focusBox", i); jQuery(".focusBox .txt li") .eq(i) .animate({ bottom: 0, }) .siblings() .animate({ bottom: -150, }); jQuery(".focusBox .pic li") .eq(i) .addClass("active") .siblings() .removeClass("active"); }, }); //轮播图 $(".bas_pc").slide({ titCell: ".num li", mainCell: ".pic", effect: "left", autoPlay: true, trigger: "click", mouseOverStop: false, vis: "auto", startFun: function (i) { // console.log("bas_pc", i); jQuery(".bas_pc .pic li") .eq(i) .addClass("active") .siblings() .removeClass("active"); }, }); //轮播图 $(".bas_phone").slide({ titCell: ".num li", mainCell: ".pic", effect: "left", autoPlay: true, trigger: "click", mouseOverStop: false, vis: "auto", startFun: function (i) { // console.log("bas_phone", i); jQuery(".bas_phone .pic li") .eq(i) .addClass("active") .siblings() .removeClass("active"); }, }); //轮播图 $(".notices").slide({ titCell: ".num li", mainCell: ".pic", effect: "left", autoPlay: true, trigger: "click", mouseOverStop: false, vis: "auto", startFun: function (i) { // console.log("notices", i); jQuery(".notices .pic li") .eq(i) .addClass("active") .siblings() .removeClass("active"); }, }); //通知 $(".notice_bas").slide({ titCell: ".num li", mainCell: ".pic", effect: "left", autoPlay: true, trigger: "click", mouseOverStop: false, vis: "auto", }); //tab切换 $(".news_tab li").click(function () { var index = $(this).index(); $(this).addClass("active").siblings().removeClass("active"); $(".tab_newscont").find(".tab_con").eq(index).show().siblings().hide(); }); //下拉框 // $(".index_slser text").click(function () { // $.each($(this).parent().siblings(), function (key, vo) { // var elem = $(vo).children(); // if (elem.children(".up").length) { // $(elem).click(); // } // }); // $(this).find("i").toggleClass("up"); // $(this).next(".selsubdlser").stop(true, false).slideToggle("fast"); // }); // $(".selsubdlser dt").click(function () { // $(this).addClass("active").siblings().removeClass("active"); // // var text = $(this).text(); // // $(this).parents(".index_slser").find(".inputselser").val(text); // $(this).parents(".index_slser").find("i").removeClass("up"); // $(this).parent(".selsubdlser").stop(true, false).slideUp("fast"); // }); // 判断是否存在样式 function hasClass(element, className) { if (element.classList) { // 现代浏览器支持classList API return element.classList.contains(className); } else { // 对于不支持classList的老旧浏览器,可以使用className字符串进行分割检查 return new RegExp('(\\s|^)' + className + '(\\s|$)').test(element.className); } } if (/Mobi|Android|iPhone/i.test(navigator.userAgent)) { // 当前设备是移动设备 var startX, startY, endX, endY; document.addEventListener("touchstart", function (e) { e = e || window.event; startX = e.changedTouches[0].clientX; startY = e.changedTouches[0].clientY; }); document.addEventListener("touchend", function (e) { e = e || window.event; endX = e.changedTouches[0].clientX; endY = e.changedTouches[0].clientY; if (Math.abs(startX - endX) < 10 || Math.abs(startY - endY) < 10) { console.log("点击屏幕"); var cr = e.target.parentNode; var obj = e.target.parentNode.parentNode; if (hasClass(obj, 'index_slser')) { console.log('点击链接'); console.log($(obj).children(".selsubdlser")); $(obj).find("i").toggleClass("up"); if ($(obj).find("i").hasClass("up")) { $(obj).children(".selsubdlser").stop(true, false).slideDown("fast"); } else { $(obj).children(".selsubdlser").stop(true, false).slideUp("fast"); } } } else { console.log("滑动屏幕"); if (startX > endX) { console.log("向左滑动屏幕"); } if (startX < endX) { console.log("向右滑动屏幕"); } if (startY > endY) { console.log("向上滑动屏幕"); } if (startY < endX) { console.log("向下滑动屏幕"); } } }); } else { $(".index_slser") .on("mouseenter", function () { $(this).find("i").toggleClass("up"); $(this).children(".selsubdlser").stop(true, false).slideDown("fast"); }) .on("mouseleave", function () { $(this).find("i").toggleClass("up"); $(this).children(".selsubdlser").stop(true, false).slideUp("fast"); }); } // 首页头条超出字符显示省略号 $(".tt-txt div").each(function () { var str = $(this).text(); var s = str; if (str.length > 15) { s = str.substring(0, 139) + "..."; } $(this).text(s); }); $(".dropdown_menu1") .on("mouseenter", function () { if ($(this).children('.dropdown_submenu').length) { $(this).parent().children().children('.dropdown_menu2').removeClass('active'); $(this).children('.actives').addClass('active'); } else { $(this).parent().children().children('.dropdown_menu2').removeClass('active'); $(this).parent().children().children('.actives').addClass('active'); } }) .on("mouseleave", function () { if ($(this).children('.dropdown_submenu').length) { $(this).parent().children().children('.dropdown_menu2').removeClass('active'); $(this).children('.actives').addClass('active'); } else { $(this).parent().children().children('.dropdown_menu2').removeClass('active'); $(this).parent().children().children('.actives').addClass('active'); } }); }); //返回顶部 function goTop() { $("body,html").animate( { scrollTop: 0, }, 1000 ); } // 左侧菜单展开收起 $(document).ready(function () { $(".collapse.in").prev(".panel-heading").addClass("active"); $("#accordion, #bs-collapse") .on("show.bs.collapse", function (a) { $(a.target).prev(".panel-heading").addClass("active"); }) .on("hide.bs.collapse", function (a) { $(a.target).prev(".panel-heading").removeClass("active"); }); }); // 漏洞修复之后script标签中内容无法运行问题调整 //注意:选项卡 依赖 element 模块,否则无法进行功能性操作 layui.use("element", function () { var element = layui.element; //… $(".layui-tab-title li").on("mouseenter", function () { $(this).addClass("layui-this").siblings().removeClass("layui-this"); var index = $(this).parent().children().index(this); $(this) .parent() .next() .children() .eq(index) .addClass("layui-show") .siblings() .removeClass("layui-show"); }); }); // 手机版导航适配相关 $(function () { $(".header_fh").click(function () { if (window.location.href.indexOf("details") !== -1) { window.history.back(); } else { window.location.href = "/"; } return false; }); function chg_nav(matches) { var arr = parse_params(window.location.search.substring(1)); if (matches && arr.catid) { // 媒体查询匹配 // 执行相关操作 console.log("chg_nav", 1); $(".header_pc").hide(); $(".header_m").show(); // // 导航宽度适配 // var lens = $(".cl_item").length; // console.log("length", lens); // if (lens == 1) { // $(".cl_item").css("min-width", "100vw"); // } else if (lens == 2) { // $(".cl_item").css("min-width", "50vw"); // } else if (lens % 5 != 1) { // $(".cl_item").css("min-width", "20vw"); // } else if (lens % 4 != 1) { // $(".cl_item").css("min-width", "25vw"); // } else if (lens % 3 != 1) { // $(".cl_item").css("min-width", "33vw"); // } // 导航宽度适配 try { var cho_nu_c = $(".cl_item.active").position().left + $(".cl_item.active").parent().scrollLeft(); cho_nu_c -= ($(".cl_item.active").parent().width() - $(".cl_item.active").width()) / 2; $(".cl_item.active").parent().scrollLeft(cho_nu_c); } catch (error) { } try { // 导航宽度适配 // 2023年12月12日 调整三级栏目 var cho_nu_c = $(".cl_sub_m .cl_item.actives").position().left + $(".cl_sub_m .cl_item.actives").parent().scrollLeft(); cho_nu_c -= ($(".cl_sub_m .cl_item.actives").parent().width() - $(".cl_sub_m .cl_item.actives").width()) / 2; $(".cl_sub_m .cl_item.actives").parent().scrollLeft(cho_nu_c); } catch (error) { } } else { // 媒体查询不匹配 // 执行其他操作 console.log("chg_nav", 2); $(".header_pc").show(); $(".header_m").hide(); // // 导航宽度适配 // $(".cl_item").css("min-width", ""); } } var mediaQuery = window.matchMedia("(max-width: 768px)"); // console.log(mediaQuery); chg_nav(mediaQuery.matches); // // 初始判断 // if (mediaQuery.matches) { // // 媒体查询匹配 // // 执行相关操作 // // console.log(11); // } else { // // 媒体查询不匹配 // // 执行其他操作 // // console.log(22); // } // 事件监听 mediaQuery.addListener(function (event) { // console.log(event); chg_nav(event.matches); // if (event.matches) { // // 媒体查询匹配 // // 执行相关操作 // // console.log(1111); // } else { // // 媒体查询不匹配 // // 执行其他操作 // // console.log(2222); // } }); }); // 手机版导航适配相关 $(function () { layui.use(["layer"], function () { layer = layui.layer; $(".navbtn").click(function () { $(".navbtn").toggleClass("on"); $("#m_nav").toggleClass("act"); $(".nav_mask").fadeToggle(); }); $("#m_nav .title .a").click(function () { var tt = $(this).parents(".title"); if ($(tt).hasClass("on")) { $(tt).children(".list").slideUp(600); //展开 $(tt).removeClass("on"); } else { $("#m_nav .title ").removeClass("on"); $("#m_nav .title .list").slideUp(); $(tt).children(".list").slideDown(); $(tt).toggleClass("on"); } // setTimeout(function () { // var p = tt.parent(); // console.log(tt.offset().top, tt.scrollTop(), (p.height() / 2)); // p.scrollTop(tt.offset().top + tt.scrollTop() + (p.height() / 2)); // }, 600); }); $(".nav_mask").click(function () { $(".navbtn").toggleClass("on"); $("#m_nav").toggleClass("act"); $(".nav_mask").fadeToggle(); }); }); }); // 处理图片裂开的问题 function img_do() { var images = document.getElementsByTagName("img"); // var zanwu = "__PUBLIC__/zanwu1.jpg"; var zanwu = "/yunqikds_static/zanwu1.jpg"; for (var i = 0; i < images.length; i++) { var img = images[i]; img.onerror = function () { console.log("error"); this.src = zanwu; }; if (!img.getAttribute("src")) { img.setAttribute("src", zanwu); img.dispatchEvent(new Event("load")); } // if (!img.complete) { // img.onerror(); // } // if (typeof img.naturalWidth !== "undefined" && img.naturalWidth === 0) { // img.onerror(); // } // if (img.onerror) { // img.addEventListener("load", function () { // this.src = zanwu; // this.removeEventListener("load", arguments.callee); // }); // img.dispatchEvent(new Event("load")); // } } } document.addEventListener("DOMContentLoaded", function () { img_do(); }); $(function () { layui.use(["layer"], function () { layer = layui.layer; $(".layui-tab-title li").click(function () { var cho_nu_c = $(this).position().left + $(this).parent().scrollLeft(); cho_nu_c -= ($(this).parent().width() - $(this).width()) / 2; $(this).parent().scrollLeft(cho_nu_c); }); }); }); // 提取参数 function parse_params(params) { var paramsArr = params.split("&"); var result = {}; paramsArr.forEach(function (param) { var paramArr = param.split("="); var paramName = decodeURIComponent(paramArr[0]); var paramValue = decodeURIComponent(paramArr[1] || ""); if (paramName.length) { if (result[paramName] !== undefined) { if (!Array.isArray(result[paramName])) { result[paramName] = [result[paramName]]; } result[paramName].push(paramValue); } else { result[paramName] = paramValue; } } }); return result; }