$(document).ready(function () { // 获取浏览器的宽度 let viewWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; // 获取地址栏,并截取地址栏最后一个"/"后面的内容 let href = window.location.href.substring(window.location.href.lastIndexOf('/') + 1); // 获取顶部/导航/导航菜单的高度 let welcomeHeight = $(".welcome").outerHeight(true); let headerHeight = $(".header").outerHeight(true); let navHeight = $("nav").outerHeight(true); let scrollTopHeight = welcomeHeight + headerHeight; // 通过地址把导航栏添加类名称 $(".nav>li").each(function (i) { let hrefNav = $("a", this).attr("href"); let lastHrefNav = hrefNav.substring(hrefNav.lastIndexOf('/') + 1); if (href === lastHrefNav) { $(this).addClass('li-active'); } }); // banner大图 let bannerSwiper = new Swiper('.banner-swiper', { slidesPerView: 1, //显示数量 loop: true, //循环轮播 autoHeight: true, //高度随内容变化 autoplay: { //自动切换 delay: 5000, //滚动时间5秒滚动一次 disableOnInteraction: false, }, pagination: { //圆点 el: '.swiper-pagination', clickable: true, }, navigation: { //箭头 nextEl: '.banner-next', prevEl: '.banner-prev', } }); // 设备展示 var equipmentSwiper = new Swiper('.equipment-swiper', { autoplay: { delay: 5000, disableOnInteraction: false, }, //自动滚动 loop: false, //循环滚动 slidesPerView: 2, //个数 spaceBetween: 5, //间距 pagination: { //圆点 el: '.swiper-pagination', clickable: true, }, breakpoints: { 1400: { slidesPerView: 4, spaceBetween: 40, }, 1200: { slidesPerView: 4, spaceBetween: 30, }, 991: { slidesPerView: 4, spaceBetween: 30, }, 767: { slidesPerView: 3, spaceBetween: 20, } } }); // 浏览器窗口宽度大于991 if (viewWidth > 991) { $(".header").css("margin-bottom", navHeight); $("nav").css("top", scrollTopHeight); // pc端导航多层下拉 $(".nav>li").hover(function () { $(this).children(".nav-child").stop().slideToggle(300); }); // pc端导航定位 $(window).scroll(function () { if ($(this).scrollTop() > scrollTopHeight) { $("nav").css({ "position": "fixed", "top": "0" }); } else { $("nav").css({ "position": "absolute", "top": scrollTopHeight }); } }) } else { // 浏览器窗口宽度小于991 $(".header").css("top", welcomeHeight); $(".welcome").css("margin-bottom", headerHeight); // 手机端导航定位 $(window).scroll(function () { if ($(this).scrollTop() > welcomeHeight) { $(".header").css({ "position": "fixed", "top": "0" }); } else { $(".header").css({ "position": "absolute", "top": welcomeHeight }); } }) // 手机端导航按钮 $(".menu-button").click(function () { if ($(this).hasClass("menu-button-active")) { $(this).removeClass("menu-button-active"); $("nav").removeClass("nav-active"); } else { $(this).addClass("menu-button-active"); $("nav").addClass("nav-active"); } }); // 手机端导航多层下拉 $(".drop-down").click(function () { $(".nav-child").stop().slideUp(300); $(this).next(".nav-child").stop().slideToggle(300); }); // 手机端左侧下拉 $(".menu-title").click(function () { $(".menu-list").slideToggle("slow"); }); } //手机端底部按钮 // 电话 $(".root .phone").click(function () { $(".root-bj").fadeIn(); $(".root-phone").slideDown(); }) $(".root-off").click(function () { $(".root-bj").fadeOut(); $(".root-phone").slideUp(); }) $(".root-bj").bind("click", function (e) { var target = $(e.target); if (target.closest(".root-phone").length == 0) { $(".root-bj").fadeOut(); $(".root-phone").slideUp(); } }) // 微信号 $(".wecht-btn").click(function () { $(".wecht-box").fadeIn(); }) $(".wecht-off").click(function () { $(".wecht-box").fadeOut(); }) $(".wecht-box").bind("click", function (e) { var target = $(e.target); if (target.closest(".wecht").length == 0) { $(".wecht-box").fadeOut(); } }) $(".wecht-btn").on("click", function () { let str = $(this).next(".wecht-box").find("#copytxt").text(); let input = ``; $("body").append(input); $("#temp").select(); document.execCommand("Copy"); $("#temp").remove(); }) }); // 返回顶部 // $(".footer-btn a").click(function() { // $('body,html').animate({ // scrollTop: 0 // },1000); // return false; // }); // // 锚链接 // $('.nav>li>a').click(function(){ // $(document).animate({scrollTop: ($($(this).attr('href')).offset().top - 0 )},1000); // }); // $('.news-nav li').hover(function () { // $(this).addClass('news-active').siblings('li').removeClass('news-active'); // var index = $(this).index(); // $('.news-contect>div').eq(index).show().siblings('.news-contect>div').hide(); // }) // var mySwiper = new Swiper('.mySwiper', { // autoplay: { // delay: 5000, // disableOnInteraction: false, // }, //自动滚动 // loop: false, //循环滚动 // slidesPerView: 3, //个数 // spaceBetween: 5, //间距 // grid: { // fill: 'row', // rows: 2, // }, // pagination: { //圆点 // el: '.swiper-pagination', // clickable: true, // }, // navigation: { //箭头 // nextEl: '.banner-next', // prevEl: '.banner-prev', // }, // breakpoints: { // 1200: { // slidesPerView: 6, // spaceBetween: 12, // }, // 1024: { // slidesPerView: 5, // }, // 767: { // slidesPerView: 4, // } // } // }); // pc端左侧多层下拉 // $(".menuList li:first").addClass("menuActive"); // $(".menuList li:first").children("ul").stop().slideDown(); // $('.menuList>li').hover(function () { // $(".menuList>li").children("ul").stop().slideUp(); // $(this).addClass('menuActive').siblings('li').removeClass('menuActive'); // $(this).children("ul").stop().slideDown() // }) // 手机端左侧多层下拉 // $(".menuList li").click(function () { // $(this).children("ul").stop(false).slideToggle(300); // })