$(function () { let mww = document.body.clientwidth; $('#whff').css('width',mww); if( mww < 1200 ){ $('#whff').css('width', '1440px'); } let mwh = window.innerheight; // 导航悬浮 $(window).scroll(function () { if ($(window).scrolltop() >= 105) { $('.hpc_nav').addclass('hpc_nav_fixed'); } else { $('.hpc_nav').removeclass('hpc_nav_fixed'); } }); // // 返回顶部 // $('.go_top').on('click', function () { // // behavior 类型string,表示滚动行为,支持参数 smooth(平滑滚动),instant(瞬间滚动),默认值auto,实测效果等同于instant // window.scrollto({ // top: 0, // left: 0, // behavior: "smooth" // }) // }); // 热门推荐 var swiper1 = new swiper('.hot_tj_bd .swiper-container', { slidesperview: 4, // 设置slider容器能够同时显示的slides数量(carousel模式) slidespergroup: 1, // 在carousel mode下定义slides的数量多少为一组 spacebetween: 20, loop: true, // 设置为true 则开启loop(无限循环)模式 freemode: true, // 设置为true则变为free模式 speed: 8000, // 匀速时间 autoplay: { // 自动播放 delay: 0, // 自动切换的时间间隔,单位ms }, }) // 实现 鼠标移入swiper-container时,轮播图停止;鼠标移出时,轮播图继续 var lastneedswiperspeed; // 平滑移动到swiper1.translate需要的速度 //鼠标移入悬停 $('.hot_tj_bd .swiper-container').on('mouseenter', function () { // swiper1.gettranslate()为当前实时的位移,swiper1.translate为过度结束的位移,swiper1.slidewidth为slide的宽度px // 计算之后平滑移动到swiper1.translate需要的速度,并储存下来 lastneedswiperspeed = math.abs(math.abs(swiper1.gettranslate()) - math.abs(swiper1.translate)) / (swiper1.slidewidth + swiper1.params.spacebetween) * swiper1.params.speed; // settranslate到当前位置,并停止autoplay swiper1.settranslate(swiper1.gettranslate()); swiper1.autoplay.stop(); // 参考文档:https://www.swiper.com.cn/api/autoplay/112.html }) //鼠标移出滚动 $('.hot_tj_bd .swiper-container').on('mouseleave', function () { // 使用刚才计算出的速度,移动到当前slide,即将当前slide的移动到头部的动画完成,开启autoplay swiper1.slideto(swiper1.activeindex, lastneedswiperspeed); swiper1.autoplay.start(); // 参考文档:https://www.swiper.com.cn/api/autoplay/111.html }) // 内页左侧菜单 $('.nav_items').on('click', function () { $(this).parents('.nav_item').find('.nav_itemy').toggle(); $(this).parents('.nav_item').siblings('.nav_item').children('.nav_itemy').stop().hide(); }); $('.show_item').on('click',function(){ $('.left_nav_box').toggle(); }); });