if ($('.e-module-202304231342').length > 0) { function module202304231342Fun($target) { var module202304231342Obj = { init: function () { // 获取属性 this.win = $(window); this.moduleObj = $target; this.fixedBoxObj = this.moduleObj.find('.fixed-box'); this.liObj = this.moduleObj.find("li"); this.headObj = $('.e-module-202209210900 .header-new'); this.anchorPointObj = $('.anchorpoint'); this.perScrollTop = 0; this.scrollLock = false; //区分是鼠标滚动还是自动滚动 this.resizeInit(); this.highlightNav(); this.clickEvent(); this.scrollEvent(); this.mouseEvent(); this.anchor(); this.resizeEvent(); }, resizeInit: function () { this.winw = this.win.width(); this.winh = this.win.height(); // 获取位置 this.scrollTop = this.win.scrollTop(); this.moduleTop = this.moduleObj.offset().top; this.docH = $(document).height(); if (this.winw > 1200) { this.moduleObj.find('.anchor').show(); } else { this.moduleObj.find('.anchor').hide(); } }, anchor: function () { var queryStr = getQueryString("section"); if (queryStr == undefined) return // 清除滚动条默认位置 if ('scrollRestoration' in history) { history.scrollRestoration = 'manual'; } this.liObj.each(function () { var _this = $(this); if (_this.data('key') == queryStr) { setTimeout(function () { _this.trigger('click'); }, 500) } }) // 获取链接参数 function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); } }, highlightNav: function () { var _this = this; // 高亮显示当前导航 var perLightHighIndex = -2; var anchorpointArr = []; _this.anchorPointObj.each(function () { //已经到达内容的一半的距离 anchorpointArr.push($(this).offset().top + $(this).height()); }) var anchorLen = anchorpointArr.length; for (var i = 0; i < anchorLen; i++) { if (_this.scrollTop <= anchorpointArr[i]) { //高亮发生改变 if (perLightHighIndex != i) { _this.liObj.eq(i).addClass('active').siblings().removeClass('active'); perLightHighIndex = i; _this.moduleObj.find('.wap-title').text(this.liObj.eq(i).text()); } break; } } // 滚动时移动端title显示当前板块 if (_this.winw < 1200) { var $titleObj = _this.moduleObj.find('.wap-title'); if (_this.liObj.eq(perLightHighIndex).text() != '') { $titleObj.text(_this.liObj.eq(perLightHighIndex).text()); } } }, mouseEvent: function () { $(".e-module-202304231342 .anchor").on("mousedown.202304231342", function (e) { var _this = $(".e-module-202304231342 .anchor"); var off = true; var curNum = 0; var scrollX = 0; $("body").on("mousemove.202304231342", function (e1) { var moveX = e1.clientX; // 判断是点击还是滚动,如果点击后鼠标滑动超过10px,我判断为鼠标滑动 if (off) { off = false; curNum = moveX; scrollX = _this.find('.sl').scrollLeft(); } //移动时的坐标减去落入时的坐标 var x = moveX - curNum; _this.find('.sl').scrollLeft(scrollX - x); }); //mouseup事件,关闭当前mousemove事件,并将定时置空 $("body").on("mouseup", function (e) { $("body").off("mousemove.202304231342"); }) }) }, clickEvent: function () { var _this = this; var clickiTime = 0; _this.liObj.on('click', function (e) { // 阻止时间冒泡 e.stopPropagation(); scrollLock = true; var li_index = $(this).index(); var head_h = _this.headObj.height(); var anchor_point_t = []; _this.anchorPointObj.each(function () { anchor_point_t.push($(this).offset().top - 70); }); var willScrollTop = anchor_point_t[li_index]; $("body,html").stop(true, true).animate({ "scrollTop": willScrollTop }); _this.headObj.clearQueue().animate({ 'top': -head_h }, 300, function () { // 高亮 _this.liObj.eq(li_index).addClass('active').siblings().removeClass('active'); var $titleObj = _this.moduleObj.find('.wap-title'); $titleObj.text(_this.liObj.eq(li_index).text()); clearTimeout(clickiTime); clickiTime = setTimeout(function () { _this.perScrollTop = _this.win.scrollTop(); scrollLock = false; }, 150) }); _this.fixedBoxObj.css({ 'position': 'fixed', }).clearQueue().animate({ 'top': 0 }, 300).parents('.e-module-202304231342').addClass('fixed'); // 移动端 if (_this.winw < 1200) { if (!_this.moduleObj.find('.anchor').is(':hidden')) { _this.moduleObj.find('.anchor').slideToggle(); } } if (_this.winw < 1200) { _this.moduleObj.find('.wap-line').toggleClass("wap-another"); } }) //移动端点击显示二级导航栏的标题,展开定位下拉 $('.e-module-202304231342 .wap-controller').on('click', function (e) { if (_this.winw < 1200) { // 阻止时间冒泡 e.stopPropagation(); $(this).nextAll('.anchor').slideToggle(); $(this).children('.wap-line').toggleClass("wap-another") } }) // 移动端点击body,如果定位导航展开,需要收起 $('body').on('click', function () { if (_this.winw < 1200) { if (!_this.moduleObj.find('.anchor').is(':hidden')) { _this.moduleObj.find('.anchor').slideToggle(); } } }) }, scrollEvent: function () { var _this = this; var timer = 0; _this.win.on('scroll.202304231342', function () { if (_this.scrollLock) { return } clearTimeout(timer); timer = setTimeout(function () { _this.scrollTop = _this.win.scrollTop(); var head_h = _this.headObj.height() + 1; var moduleTop = _this.moduleObj.offset().top - _this.moduleObj.height(); _this.docH = $(document).height(); var winh = _this.winh * 1.5; // 判断滚动条是往上还是往下滚动 if (_this.scrollTop - _this.perScrollTop >= 3) { //向下 // 判断滚动条滚动到什么位置 if (_this.scrollTop + head_h > moduleTop && _this.scrollTop < (_this.docH - winh)) { //顶部交界处 // 计算滚动条移动的位置 _this.headObj.clearQueue().animate({ 'top': -head_h }, 300); _this.fixedBoxObj.css({ 'position': 'fixed' }).clearQueue().animate({ 'top': 0 }, 300).parents('.e-module-202304231342').addClass('fixed'); } else if ((_this.docH - _this.scrollTop) <= winh) { //底部交界处 _this.headObj.clearQueue().animate({ 'top': 0 }, 300); _this.fixedBoxObj.css({ 'position': 'fixed', }).clearQueue().animate({ 'top': head_h }, 300).parents('.e-module-202304231342').addClass('fixed'); } } else if (_this.scrollTop - _this.perScrollTop <= -3) { //向上 // 判断滚动条滚动到什么位置 if (_this.scrollTop - head_h - _this.moduleObj.height() < moduleTop) { //顶部交界处 // 计算滚动条移动的位置 _this.headObj.clearQueue().animate({ 'top': 0 }, 300); _this.fixedBoxObj.stop(true).css({ 'position': 'absolute', 'top': '0px' }).parents('.e-module-202304231342').removeClass('fixed'); } else if ((_this.docH - _this.scrollTop) >= winh) { //底部交界处 _this.headObj.clearQueue().animate({ 'top': 0 }, 300); _this.fixedBoxObj.css({ 'position': 'fixed', }).clearQueue().animate({ 'top': head_h }, 300).parents('.e-module-202304231342').addClass('fixed'); } } _this.highlightNav(); _this.perScrollTop = _this.scrollTop; }, 0) }) }, resizeEvent: function () { // 页面resize事件 var _this = this; var resizeWinw = 0; var resizeTimer = ''; this.win.on('resize.202304231342', function () { var winw = _this.win.width(); if (winw != resizeWinw) { currentWinw = winw; // 删除之前的定时器 if (resizeTimer) { clearTimeout(resizeTimer); } // 添加新的定时器 resizeTimer = setTimeout(function () { _this.resizeInit(); }, 100) } }) } }; module202304231342Obj.init(); } // 初始化 $('.e-module-202304231342').each(function () { // 防止js文件被执行2次。 var _this = $(this); if (_this.data('init')) { return; } _this.data('init', true); module202304231342Fun($(this)); }) }