// 10.21 start $(function () { redirectbylang(); //20210830 婕忔礊 $(".mc_botbox_btn").click(function () { $(".mc_botbox").stop().fadeOut(); $.cookie('isHide', 'true'); }); var isHide = $.cookie('isHide'); if (isHide) { $(".mc_botbox").stop().hide(); } else { $(".mc_botbox").stop().show(); } }); // 10.21end $(function () { // wow鍒濆鍖 new WOW().init(); // 鎵嬫満瀵艰埅涓嬫媺 phMenu(); mcCheckbox(); pcNav(); ftInit(); xlSearch(); initNavLine(); // 鐐瑰嚮閬僵灞傛敹璧 $('.load-mask').click(function (e) { e.stopPropagation(); $('.point').removeClass('active') $('.xialaph').stop().slideUp() $('.phonemeng').removeClass('active') $('html').removeClass('modal-open') $('.load-mask').stop().fadeToggle() // 鏀惰捣鍙宠竟 $('.sub-nav').slideUp() // 鎶婂乏杈归鑹插拰閫変腑鍘绘帀 $('.ul1') .children() .children() .children() .removeClass('nav-active') .children('a') .removeClass('nav-a-active') $('.ul1').children().children().children().find('.active-line').hide() // 鍏抽棴寮圭獥杩樺師涓夌骇鑿滃崟鐨勬牱寮 if (!$('html').hasClass('modal-open')) { $('.sub-nav-icon') .find('img') .attr('src', '../../templates/leewelltech/image/mob/nav/arrow-down.png') $('.sub-nav-container > li').removeClass('isopen') } if ($('.search-float').css('display') != 'none') { $('.search-float').css('display', 'none') } }) }); function redirectbylang() { var domain = window.location.href;//鑾峰彇褰撳墠鍦板潃 var host = window.location.host;//褰撳墠鍩熷悕 var ref = document.referrer; //鑾峰彇褰撳墠娴忚鍣ㄨ瑷€ var currentLang = navigator.language; if(!currentLang){ currentLang = navigator.browserLanguage; } //鍒ゆ柇鏄惁鏈塴anguage cookie var haslang = false; var isenglish = false; if($.cookie('language')) { haslang = true; if($.cookie('language').indexOf("en") > -1){ //鍒ゆ柇鏄惁涔嬪墠瀛樼殑en鐨刢ookie isenglish = true; } } //鍒ゆ柇鏄惁鏄潵婧愪簬鏈珯 var islocal = false; if(ref && ref.indexOf(host) > -1){ islocal = true; } //鍖哄垎鏄惁鏄埛鏂帮紙鍗虫湰椤甸潰鐐瑰嚮鍒锋柊锛屼篃涓虹粺涓€娴忚鍣ㄥ埛鏂版湁鏉ヨ矾鍜屽洖杞︽棤鏉ヨ矾闂锛 if(window.performance.navigation.type == 1){ islocal = false; } //鍒ゆ柇鏄惁鏄椤 浠呭湪棣栭〉鎵ц鎵€鏈夐€昏緫 if(domain == "https://"+host+"/" || domain == "http://"+host+"/"){ if(!haslang){//娌℃湁璇█cookie //鍒ゆ柇娴忚鍣ㄨ瑷€鏄惁鏄腑鏂 if(currentLang.indexOf("zh") == -1){ if(!islocal) { //澶囨敞锛氶€氳繃 window.location.href 锛寃af鍜宑dn鏃犳硶鑾峰彇鏉ユ簮 $.cookie('language', 'en',{path:"/"}); window.location.href = "http://" + host + "/html/en/"; return false; } } //璁剧疆cookie $.cookie('language', 'cn',{path:"/"}); //鏄剧ず棣栭〉body $("body").css("visibility","visible"); }else{ //濡傛灉涓嶆槸鏈湴鏉ヨ矾涓攃ookie瀛樼殑鑻辨枃 if(!islocal && isenglish){ window.location.href = "http://"+host+"/html/en/"; }else{ //鏄剧ず棣栭〉body $('body').css('visibility', 'visible') $.cookie('language', 'cn', { path: '/' }) } } } } // 鎵嬫満瀵艰埅涓嬫媺 function phMenu() { // ph瀵艰埅 $('.mc_ph_menu').click(function (e) { e.stopPropagation() // 11.19 var h = window.innerHeight - 64 // $(".xialaph").css("height", h + "px"); $('.xialaph').css('height', '440px') // 11.19 $(this).find('.point').toggleClass('active') $('.xialaph').stop().slideToggle() $('.phonemeng').toggleClass('active') $('html').toggleClass('modal-open') $('.load-mask').fadeToggle() // 鏀惰捣鍙宠竟 $('.sub-nav').slideUp() // 鎶婂乏杈归鑹插拰閫変腑鍘绘帀 $('.ul1') .children() .children() .children() .removeClass('nav-active') .children('a') .removeClass('nav-a-active') $('.ul1').children().children().children().find('.active-line').hide() // 鍏抽棴寮圭獥杩樺師涓夌骇鑿滃崟鐨勬牱寮 if (!$('html').hasClass('modal-open')) { $('.sub-nav-icon') .find('img') .attr('src', '../../templates/leewelltech/image/mob/nav/arrow-down.png') $('.sub-nav-container > li').removeClass('isopen') } let isEn = window.location.pathname && window.location.pathname.includes('en'); let search = window.location.search || ''; let searchList = search.split('tid=')[1] ? search.split('tid=') : (!search.split('tid=')[1] ? search.split('did=') : []) || [] let aboutCompanyPage = isEn ? ['85'] : ['45']; let newsPage = isEn ? ['79', '80'] : ['61', '62']; let solutionPage = isEn ? ['86', '87', '88', '89'] : ['74', '75', '76', '77']; let productPage = isEn ? ['127', '128', '129', '130'] : ['96', '97', '98', '99']; let servicePage = isEn ? ['95'] : ['54']; // 濡傛灉鏄椤靛垯榛樿閫変腑棣栭〉锛屼笖鍙宠竟涓嶅嚭鐜颁笢瑗 if (!search && $(e.target).eq(0).hasClass('active')) { $('.ul1') .children() .children() .children('h4') .eq(0) .find('.active-line') .slideDown() $('.ul1') .children() .children() .children('h4') .eq(0) .addClass('nav-active') $('.ul1') .children() .children() .children('h4') .eq(0) .children('a') .addClass('nav-a-active') } else { let idx = 0 if (search && aboutCompanyPage.includes(searchList[1])) { idx = 1 } else if (search && newsPage.includes(searchList[1])) { idx = 2 } else if (search && solutionPage.includes(searchList[1])) { idx = 3 } else if (search && productPage.includes(searchList[1])) { idx = 4 } else if (search && servicePage.includes(searchList[1])) { idx = 5 } $('.ul1') .children() .children() .children('h4') .eq(idx) .find('.active-line') .slideDown() $('.ul1') .children() .children() .children('h4') .eq(idx) .addClass('nav-active') $('.ul1') .children() .children() .children('h4') .eq(idx) .children('a') .addClass('nav-a-active') } // 榛樿杩涙潵鎵€鏈変笅鎷夐殣钘 $('.submenu').hide() if ($('.sub-nav-container > li').hasClass('no-submenu')) { $('.sub-nav-container > li') .children('.sub-nav-icon') .find('img') .hide() $('.sub-nav-container > li') .siblings('li') .children('.sub-nav-icon') .find('img') .hide() } // 鎵嬮鐞 $('.sub-nav-container > li') .unbind('click') .bind('click', function (e) { if ($(this).hasClass('no-submenu')) { return } $(this).next('.submenu').slideToggle() $(this).siblings('li').next('.submenu').slideUp() // 澧炲姞杩欎釜绫诲彧鏄负浜嗗尯鍒嗗睍寮€鐨勯」 $(this) .toggleClass('isopen') .siblings('li') .removeClass('isopen') if ($(this).hasClass('isopen')) { $(this) .children('.sub-nav-icon') .find('img') .attr('src', '../../templates/leewelltech/image/mob/arrow-up.png') $(this) .siblings('li') .children('.sub-nav-icon') .find('img') .attr('src', '../../templates/leewelltech/image/mob/arrow-down.png') } else { $(this) .children('.sub-nav-icon') .find('img') .attr('src', '../../templates/leewelltech/image/mob/arrow-down.png') } }) $('.submenu > li') .unbind('click') .bind('click', function (e) { e.stopPropagation() }) return }) // ph瀵艰埅浜岀骇 $('.xialaph h4').click(function (e) { // 棣栭〉鍙宠竟娌′笢瑗 if (!$(e.target).text().includes('棣栭〉')) { // 閫変腑鐨勫搴旂殑鍙宠竟鍐呭 $(this).parent().children('.sub-nav').slideDown() $(this).parent().parent().siblings().find('.sub-nav').hide() } else { $('.sub-nav').slideUp() } if ( $(this) .siblings('.sub-nav') .children('.sub-nav-container') .children('li') .hasClass('no-submenu') ) { $(this) .siblings('.sub-nav') .children('.sub-nav-container') .children('li') .children('.sub-nav-icon') .find('img') .hide() $(this) .siblings('.sub-nav') .children('.sub-nav-container') .children('li') .siblings('li') .children('.sub-nav-icon') .find('img') .hide() } else { $(this) .siblings('.sub-nav') .children('.sub-nav-container') .children('li') .children('.sub-nav-icon') .find('img') .show() $(this) .siblings('.sub-nav') .children('.sub-nav-container') .children('li') .siblings('li') .children('.sub-nav-icon') .find('img') .show() } // 閫変腑鐨勭嚎娈靛嚭鐜 $(this).find('.active-line').slideDown() $(this).parent().parent().siblings().find('h4').find('span').hide() // 閫変腑鐨勮儗鏅嚭鐜 $(this) .parent() .parent() .siblings() .find('h4') .removeClass('nav-active') $(this).addClass('nav-active') // 閫変腑鐨勯鑹 $(this) .parent() .parent() .siblings() .find('h4') .children('a') .removeClass('nav-a-active') $(this).children('a').addClass('nav-a-active') return if ($(e.target).hasClass('g_phnav1')) { return } if ($(this).parents('li').hasClass('mc_phnav_hasnosub')) { return } $(this).siblings('.ul2').stop().slideToggle() $(this).parent().parent().siblings().find('.ul2').stop().slideUp() $(this).toggleClass('active') $(this).parent().parent().siblings().find('h4,h5').removeClass('active') }) /*ph瀵艰埅涓夌骇*/ $('.xialaph h5').click(function () { $(this).siblings('.ul3').stop().slideToggle() $(this).parent().siblings().find('.ul3').stop().slideUp() $(this).toggleClass('active') $(this).parent().siblings().find('h4,h5').removeClass('active') }) // $(".ul1>li").each(function () { // if ($(this).find(".ul2 li").length == 0) { // $(this).addClass("mc_phnav_hasnosub"); // } // }) $('.xialaph h4 a').click(function (e) { // e.stopPropagation() }) } // 鍒濆鍖栧鑸爮鐨勭嚎鏉 function initNavLine () { $('.mc_nav_li').removeClass('zdpc-nav-active'); let isEn = window.location.pathname && window.location.pathname.includes('en'); let search = window.location.search || ''; let searchList = search.split('tid=')[1] ? search.split('tid=') : (!search.split('tid=')[1] ? search.split('did=') : []) || []; let aboutCompanyPage = isEn ? ['85', '81'] : ['45']; let newsPage = isEn ? ['79', '80'] : ['61', '62']; let solutionPage = isEn ? ['86', '87', '88', '89'] : ['74', '75', '76', '77']; let productPage = isEn ? ['127', '128', '129', '130'] : ['96', '97', '98', '99']; let servicePage = isEn ? ['95'] : ['54']; let idx = 0; // 濡傛灉鏄椤 if (!search) { idx = 0 } else { if (search && aboutCompanyPage.includes(searchList[1])) { idx = 1 } else if (search && newsPage.includes(searchList[1])) { idx = 2 } else if (search && solutionPage.includes(searchList[1])) { idx = 3 } else if (search && productPage.includes(searchList[1])) { idx = 4 } else if (search && servicePage.includes(searchList[1])) { idx = 5 } } $('.mc_nav_li').eq(idx).addClass('zdpc-nav-active').siblings().removeClass('zdpc-nav-active'); } // checkbox function mcCheckbox() { $('.mc_ly_checkbox') .find('input') .click(function (e) { e.stopPropagation() }) $('.mc_ly_checkbox').click(function () { $(this).find('input').click() }) //鍗曢€ 2021.1.26 mark $('.mc_ly_yycj .mc_ly_checkbox').click(function () { $(this).siblings().find('input[type=checkbox]').removeAttr('checked') }) } // 閿氱偣 function yxtop() { $(window).load(function () { var test = window.location.href.split('tp/') if (!isNaN(test[1])) { $('html,body').animate( { scrollTop: $('[yxdatop-pag="' + test[1] + '"]').offset().top - 90, }, 700 ) } }) } // pc瀵艰埅鐩稿叧 function pcNav() { // 瀵艰埅鍚搁《 navFixed() $(window).scroll(function () { navFixed() }) function navFixed() { if ($(window).scrollTop() > 0) { $('.mc_navbar').addClass('mc_fixed') $('.mc_logo_def').attr("src", "/templates/leewelltech/image/lleewelltech_logo.svg" ); $('.mc_logo_fixed').attr("src", "/templates/leewelltech/image/lleewelltech_logo.svg" ); } else { $('.mc_logo_def').attr("src", "/templates/leewelltech/image/lleewelltech_logo_white.svg" ); $('.mc_logo_fixed').attr("src", "/templates/leewelltech/image/lleewelltech_logo_white.svg" ); if ($('.mc_navbar').hasClass('hovernow')) { $('.mc_logo_def').attr("src", "/templates/leewelltech/image/lleewelltech_logo.svg" ); $('.mc_logo_fixed').attr("src", "/templates/leewelltech/image/lleewelltech_logo.svg" ); return } $('.mc_navbar').removeClass('mc_fixed') } } $('.mc_navbar').hover( function () { $(this).addClass('hovernow') $('.mc_logo_def').attr("src", "/templates/leewelltech/image/lleewelltech_logo.svg" ); $('.mc_logo_fixed').attr("src", "/templates/leewelltech/image/lleewelltech_logo.svg" ); if ($(window).scrollTop() == 0) { $(this).addClass('mc_fixed mc_nav_hover') } }, function () { $(this).removeClass('hovernow') // 榧犳爣绉诲嚭锛岄渶瑕佸睍绀虹伆鑹插瓧 $('.mc_logo_def').attr("src", "/templates/leewelltech/image/lleewelltech_logo.svg" ); $('.mc_logo_fixed').attr("src", "/templates/leewelltech/image/lleewelltech_logo.svg" ); if ($(window).scrollTop() == 0) { // 榧犳爣绉诲嚭锛岄渶瑕佸睍绀虹伆鑹插瓧锛屽鏋滄槸椤堕儴鍒欑户缁睍绀虹櫧鑹插瓧 $(this).removeClass('mc_fixed') $('.mc_logo_def').attr("src", "/templates/leewelltech/image/lleewelltech_logo_white.svg" ); $('.mc_logo_fixed').attr("src", "/templates/leewelltech/image/lleewelltech_logo_white.svg" ); } $(this).removeClass('mc_nav_hover') } ) // 浜岀骇涓嬫媺 $('.mc_nav_li') .not('.yxnav_active1') .hover( function () { // if ($(window).scrollTop() == 0) { // $(".mc_navbar").addClass("mc_fixed") // } $(this).find('.mc_nav_xl').stop().slideDown().addClass('show') $('.mc_nav_li.yxnav_active1') .find('.mc_nav_xl') .addClass('xlhide') }, function () { // if ($(window).scrollTop() == 0) { // $(".mc_navbar").removeClass("mc_fixed") // } $(this).find('.mc_nav_xl').stop().slideUp().removeClass('show') $('.mc_nav_li.yxnav_active1') .find('.mc_nav_xl') .removeClass('xlhide') } ) $('.mc_subnav_li') .not('.yxnav_active1') .hover( function () { // if ($(window).scrollTop() == 0) { // $(".mc_navbar").addClass("mc_fixed") // } $(this).find('.mc_nav_xl-3').stop().slideDown().addClass('show') $('.mc_nav_xl-3.yxnav_active1') .find('.mc_nav_xl-3') .addClass('xlhide') }, function () { // if ($(window).scrollTop() == 0) { // $(".mc_navbar").removeClass("mc_fixed") // } $(this) .find('.mc_nav_xl-3') .stop() .slideUp() .removeClass('show') $('.mc_nav_xl-3.yxnav_active1') .find('.mc_nav_xl-3') .removeClass('xlhide') } ) // 鎼滅储涓嬫媺 var isShow = false $('.mc_search').click(function (e) { e.stopPropagation() if (!isShow) { $(this).addClass('isshow') $(this).find('.mc_search_xl').stop().slideDown().addClass('show') isShow = true } else { $(this).removeClass('isshow') $(this).find('.mc_search_xl').stop().slideUp().removeClass('show') isShow = false } }) $('.mc_search_xl').click(function (e) { e.stopPropagation() }) $('.mc_search_xl').mouseleave(function () { $(this).parents('.mc_search').removeClass('isshow') $(this).stop().slideUp().removeClass('show') isShow = false }) } //搴曢儴鐩稿叧 function ftInit() { // 搴曢儴浜岀淮鐮佹樉绀 if ($(window).width() > 1200) { $('.mc_ft1_qrbox').hover( function () { $(this).find('.mc_ft1_qrxl').stop().slideDown() }, function () { $(this).find('.mc_ft1_qrxl').stop().slideUp() } ) } else { $('.mc_ft1_qrbox').click(function (e) { e.stopPropagation() $(this).siblings().find('.mc_ft1_qrxl').stop().slideUp() $(this).find('.mc_ft1_qrxl').stop().slideToggle() }) $('body').click(function () { $('.mc_ft1_qrxl').stop().slideUp() }) } } // 鍔ㄦ€佷慨鏀圭Щ鍔ㄧ杞挱icon鐨剋idth function initSwiperIconWid(swiperWarp) { let slideList = $(swiperWarp) .children('.swiper-wrapper') .children('.swiper-slide') $.each(slideList, function (idx, obj) { let iconNum = $(obj) .children('.slide-content') .children('.slide-btm') .children('.slide-btm-features') .children().length let wid = (100 / iconNum).toFixed(1) $(obj) .children('.slide-content') .children('.slide-btm') .children('.slide-btm-features') .children() .css('width', `${wid}%`) }) } //瀵艰埅hover鏁堟灉 $(function () { $('.mc_nav_li').click(function () { $(this).addClass('zdpc-nav-active').siblings().removeClass('zdpc-nav-active') }) }) function navHover() { var $line = $('') if ($('.mc_nav_line').length < 1) { $('.mc_nav').append($line) } var linePara = { widthArr: [], leftArr: [], leftAct: 0, widthAct: 0, } getLinePara() lineInit() $(window).load(function () { getLinePara() lineInit() }) $(window).resize(function () { getLinePara() lineInit() }) $('.mc_nav_li').hover( function () { var index = $(this).index() setLinePara(linePara.leftArr[index], linePara.widthArr[index]) }, function () { lineInit() } ) // 绾垮垵濮嬪寲 function lineInit() { setLinePara(linePara.leftAct, linePara.widthAct) } // 鑾峰彇绾跨殑left鍜寃idth鍙傛暟 function getLinePara() { linePara.widthArr = [] linePara.leftArr = [] $('.mc_nav>.mc_nav_li').each(function () { var itemLeft = $(this).position().left linePara.leftArr.push(itemLeft) var itemWidth = $(this).outerWidth() linePara.widthArr.push(itemWidth) if ($(this).hasClass('yxnav_active1')) { linePara.leftAct = itemLeft linePara.widthAct = itemWidth } }) } //璁惧畾绾跨殑鍙傛暟 function setLinePara(itemLeft, itemWidth) { $line.css({ left: itemLeft, width: itemWidth, }) } } //鍓嶆部鎶€鏈紙鐮斿彂锛夊線涓婄Щ鍔ㄦ晥鏋 $(function () { dataTable() }) $(window).load(function () { dataTable() }) function dataTable() { if ($('.mc_data_td').length > 0) { var dataTopArr = [] getTopArr() isDataShow() $(window).resize(function () { getTopArr() }) $(window).scroll(function () { isDataShow() }) // 鍒ゆ柇鏄惁鏄剧ず function isDataShow() { for (var i = 0; i < dataTopArr[length]; i++) { if ($(window).scrollTop() > dataTopArr[i]) { $('.mc_data_td').eq(i).addClass('active') } else { $('.mc_data_td').eq(i).removeClass('active') } } } // 鑾峰彇鍏冪礌璺濈椤堕儴鐨勯珮搴 function getTopArr() { $('.mc_data_td').each(function (index) { var itemIndex = index var itemTop = $(this).offset().top - $(window).height() / 1.5 dataTopArr[itemIndex] = itemTop }) } } } //鍓嶆部鎶€鏈紙鐮斿彂锛夊線涓婄Щ鍔ㄦ晥鏋 $(function () { g1List() }) $(window).load(function () { g1List() }) function g1List() { if ($('.mc_g1_li').length > 0) { var dataTopArr = [] getTopArr() isDataShow() $(window).resize(function () { getTopArr() }) $(window).scroll(function () { isDataShow() }) // 鍒ゆ柇鏄惁鏄剧ず function isDataShow() { for (var i = 0; i < dataTopArr[length]; i++) { if ($(window).scrollTop() > dataTopArr[i]) { $('.mc_g1_li').eq(i).addClass('active') } else { $('.mc_g1_li').eq(i).removeClass('active') } } } // 鑾峰彇鍏冪礌璺濈椤堕儴鐨勯珮搴 function getTopArr() { $('.mc_g1_li').each(function (index) { var itemIndex = index var itemTop = $(this).offset().top - $(window).height() / 1.5 dataTopArr[itemIndex] = itemTop }) } } } // 鏇村妗堜緥 function moreCase() { var tool = '
' + '
' + '' + 'MORE' + '
' + '
' + '' + '
' + '
' $('.mc_btn_list').each(function () { if ($(this).find('.mc_btn_li').length > 4) { $(this).append(tool) } }) $('.mc_btn_list').on('click', '.mc_btn_show', function () { $(this) .hide() .parent('.mc_btn_toggle') .siblings('.mc_btn_li') .css('display', 'inline-block') $(this).siblings('.mc_btn_hide').show() }) $('.mc_btn_list').on('click', '.mc_btn_hide', function () { $(this) .hide() .parent('.mc_btn_toggle') .siblings('.mc_btn_li:gt(3)') .hide() $(this).siblings('.mc_btn_show').show() }) } // 9.2 function xlSearch() { $('#serachs').click(function () { var keywords = $('#keywords').val() if (keywords.length == 0) { alert('Please enter key words锛?) } else { window.location.href = '/search/?' + keywords } }) $('#keywords').keyup(function (event) { if (event.keyCode == 13) { $('#serachs').trigger('click') } }) } // searchInit(); function searchInit() { var keywords = window.location.search keywords = decodeURI(keywords.replace('?', '')) $('#text').val(keywords) if (!keywords) { return false } serach() } //20210702涓嬫媺 $(function () { globleXl() }) function globleXl() { if ($(window).width() > 1024) { $('.mc1_area').hover( function () { $(this).addClass('act') $('.mc1_area_second').stop().slideDown() if ($('.mc_search').hasClass('isshow')) { $('.mc_search').trigger('click') } }, function () { $(this).removeClass('act') $('.mc1_area_second').stop().slideUp() } ) $('.mc1_area_sec_li').hover( function () { $(this).find('.mc1_area_third').stop().fadeIn() }, function () { $(this).find('.mc1_area_third').stop().fadeOut() } ) } else { $('.mc1_area').click(function (e) { e.stopPropagation() $(this).toggleClass('act') }) $('.mc1_area_sec_li').click(function (e) { e.stopPropagation() $(this).find('.mc1_area_third').stop().fadeToggle() }) $('.mc1_area_second').click(function (e) { e.stopPropagation() }) $('.mc1_area_back').click(function () { $('.mc1_area').removeClass('act') }) $('.mc_ph_menu').click(function () { $('.mc1_area').removeClass('act') }) } } // 2022.3.4 ;(function (window) { var myScrollbar if (window.myScrollbar) { myScrollbar = window.myScrollbar } myScrollbar = { $html: $('html'), $body: $('body'), originalBodyPad: null, scrollbarWidth: 0, hide: function () { this.$body = $('body') this.checkScrollbar() this.setScrollbar() this.$html.css('overflow', 'hidden') }, show: function () { this.$body = $('body') this.$html.removeAttr('style') this.resetScrollbar() }, checkScrollbar: function () { var fullWindowWidth = window.innerWidth if (!fullWindowWidth) { var documentElementRect = document.documentElement.getBoundingClientRect() fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left) } this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth this.scrollbarWidth = this.measureScrollbar() }, setScrollbar: function () { var bodyPad = parseInt(this.$body.css('padding-right') || 0, 10) this.originalBodyPad = document.body.style.paddingRight || '' if (this.bodyIsOverflowing) this.$body.css('padding-right', bodyPad + this.scrollbarWidth) }, measureScrollbar: function () { var scrollDiv = document.createElement('div') scrollDiv.style.position = 'absolute' scrollDiv.style.top = '-9999px' scrollDiv.style.width = '50px' scrollDiv.style.height = '50px' scrollDiv.style.overflow = 'scroll' this.$body.append(scrollDiv) var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth this.$body[0].removeChild(scrollDiv) console.log(scrollbarWidth) return scrollbarWidth }, resetScrollbar: function () { this.$body.css('padding-right', this.originalBodyPad) }, isMobileSafari: function () { var ua = navigator.userAgent.toLowerCase() var isChrome = ua.indexOf('chrome') != -1 var isSafari = ua.indexOf('safari') != -1 var isMobile = ua.indexOf('safari') != -1 if (!isChrome && isSafari && isMobile) { return 1 } else { return 0 } }, } window.myScrollbar = myScrollbar })(window)