function getTop(e) { var offset = e.offsetTop; if (e.offsetParent != null) offset += getTop(e.offsetParent); return offset; } function bindEvents() { var scrollFun = function () { var t = $(window).scrollTop(); var menuTop = getTop($('.page-list')[0]); // console.log(t, menuTop); var radio = $(window).width() / 1920; var footer = $('footer').height(); var leftHeight = $('.left-menus').height(); var wh = $(window).height(); var maxh = $(document.body).height(); if (t + 100 >= menuTop) { $('.left-menus').addClass('fixed'); } else { $('.left-menus').removeClass('fixed'); } var diff = maxh - footer - $(window).scrollTop(); t = diff - (leftHeight + 100); var l = 0; if (t > 100) { t = 100; } if ($('.left-menus').hasClass('fixed')) { l = $('.page-list').offset().left; } else { t = 0; } console.log(t, diff); $('.left-menus').css({ top: t, left: l }); // var xinian_conTop = getTop($(".xinian_con")[0]); // var qyjzg_conTop = getTop($(".qyjzg_con")[0]); // if (t + 400 * radio >= qyjzg_conTop) { // $(".left-menus .menu-item").removeClass("active"); // $(".left-menus .menu-item").eq(2).addClass("active"); // } else if (t + 400 * radio >= xinian_conTop) { // $(".left-menus .menu-item").removeClass("active"); // $(".left-menus .menu-item").eq(1).addClass("active"); // } else { // $(".left-menus .menu-item").removeClass("active"); // $(".left-menus .menu-item").eq(0).addClass("active"); // } checkBox(); }; $(window).scroll(function () { scrollFun(); }); $(window).resize(function () { scrollFun(); }); } function isInViewport(element) { var t = $(window).scrollTop(); var h = $(window).height(); var elTop = getTop(element); var radio = $(window).width() / 1920; if (t + h * 0.666 > elTop) { return true; } else { return false; } } function checkBox() { var elements = document.querySelectorAll('.box'); for (var i = 0; i < elements.length; i++) { var element = elements[i]; if (isInViewport(element)) { element.classList.add('inBox'); } else { element.classList.remove('inBox'); } } } const toDevelopment = function () { window.location.href = '/content/china/accl/amwayChinaV2/about/companyCulture/amwayDevelopment.html'; }; const toMessage = function () { window.location.href = '/content/china/accl/amwayChinaV2/about/companyCulture/amwayMessage.html'; }; const bindSwiper = function () { // var swiper = new Swiper('.mySwiper', { // slidesPerView: 4, // spaceBetween: 0, // pagination: { // el: '.swiper-pagination', // clickable: true // } // }); var swiper = null; var resizeSwiper = function () { var w = $(window).width(); var perView = 4; if (w <= 1024) { perView = 1.3; } else { perView = 4; } if (swiper == null) { swiper = new Swiper('.mySwiper', { slidesPerView: perView, spaceBetween: 0, pagination: { el: '.swiper-pagination', clickable: true } }); } else { console.log(swiper); swiper.params.slidesPerView = perView; swiper.update(true); } }; $(window).resize(function () { resizeSwiper(); }); resizeSwiper(); }; const toPtys = function(){ window.location.href = '/content/china/accl/amwayChinaV2/amwayBusiness/business/businessAdvantages.html'; } const toXfbz = function(){ window.location.href = '/content/china/accl/amwayChinaV2/amwayBusiness/business/businessSecurity.html'; } const toCygf = function(){ window.location.href = '/content/china/accl/amwayChinaV2/amwayBusiness/business/businessStandard.html'; } const toYhgk = function(){ window.location.href = '/content/china/accl/amwayChinaV2/amwayBusiness/business/businessPreferential.html'; } const toJiniance = function(){ window.location.href = '/content/china/accl/amwayChinaV2/zh-CN/about/amwayChina/thirtyYear.html'; } $(function () { bindSwiper(); // bindEvents(); // checkBox(); });