$(function() { if (browserRedirect()) { // 绉诲姩鐗堝ご閮ㄥ鑸 $('.nav-ul>li').each(function(index, item) { if ($(this).find('.sub-nav li').length > 0) { var $a = $(this).children('a') $('arrow').appendTo($a); $a.attr('href', 'javascript:;'); $a.click(function() { $(this).siblings('.sub-nav').slideToggle(300); $(this).children('.icon').toggleClass('active'); }); } }); $('#listBtn,.mask,#closeBtn').click(function() { $('.mask').fadeToggle(); $('#nav').toggleClass('active'); }); $('#listBtn').click(function() { $('html').addClass('noscroll'); }); $('.mask,#closeBtn').click(function() { $('html').removeClass('noscroll'); }); // 鎵嬫満鐗堝唴瀹瑰浘鐗囨斁澶ч瑙 $('.page-cont .p-content img').click(function(){ var src = $(this).attr('src'); previewImg(src); }); // 鐐瑰嚮璇█鑿滃崟鐨勫閮ㄧ缉鍥炶瑷€鑿滃崟 $('body').click(function(){ $('.language_list').slideUp(300); }); // 璇█鍒囨崲 $('.language_list').on('click','li',function(e){ e.stopPropagation(); var dLang = $('#languageBtn').attr('data-val'); var lang_val = $(this).attr('data-val'); if(dLang != lang_val){ var lang_html = $(this).html(); $('#languageBtn').attr('data-val', lang_val).html(lang_html); window.location.href = $(this).attr('data-href'); } $('.language_list').slideUp(300); }); // 灞曠ず鍏ㄩ儴璇█ $('#languageBtn').click(function(e){ e.stopPropagation(); $('.language_list').slideToggle(300); }); } else { // pc澶撮儴涓嬫媺鑿滃崟 var aMenuOneLi = $(".nav-ul > li"); var aMenuTwo = $(".sub-nav"); $(".nav-ul > li").each(function(i) { $(this).hover( function() { $(aMenuTwo[i - 1]).show(); }, function() { $(aMenuTwo[i - 1]).hide(); } ); }); // 璇█鍒囨崲 $('.language_list').on('click', 'li', function(){ if(!$(this).hasClass('active')){ $(this).addClass('active').siblings('li').removeClass('active'); window.location.href = $(this).attr('data-href'); } }); // 鍥炲埌椤堕儴 toTop('#topBtn'); $('#sideBar .code_btn>a').hover(function(){ $(this).siblings('img').fadeIn(300); },function(){ $(this).siblings('img').fadeOut(300); }); } }); ///妫€娴嬫槸鍚︾Щ鍔ㄨ澶囨潵璁 function browserRedirect(ab, cs) { var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os"; var bIsMidp = sUserAgent.match(/midp/i) == "midp"; var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb"; var bIsAndroid = sUserAgent.match(/android/i) == "android"; var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"; var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile"; if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) { return true; } else { return false; } } function previewImg(csrc){ var pswpElement = document.querySelectorAll('.pswp')[0]; var items = []; var index = 0; //鑾峰彇鍥剧墖鏁版嵁骞跺~鍏呰繎鏁扮粍 $('.page-cont .p-content img').each(function(i,eimg){ if(eimg.getAttribute('src') == csrc){ index = i; } var imgObj = {src:eimg.getAttribute('src'), w:eimg.naturalWidth, h:eimg.naturalHeight}; items.push(imgObj); }); var options = {index: index}; var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items ,options); gallery.init(); } /** * 闃叉姈鍑芥暟 * @param method 浜嬩欢瑙﹀彂鐨勬搷浣 * @param delay 澶氬皯姣鍐呰繛缁Е鍙戜簨浠讹紝涓嶄細鎵ц * @returns {Function} */ function debounce(method, delay) { let timer = null; return function () { let self = this, args = arguments; timer && clearTimeout(timer); timer = setTimeout(function () { method.apply(self, args); }, delay); } } /** * 鑺傛祦鍑芥暟 * @param method 浜嬩欢瑙﹀彂鐨勬搷浣 * @param mustRunDelay 闂撮殧澶氬皯姣闇€瑕佽Е鍙戜竴娆′簨浠 */ function throttle(method, mustRunDelay) { let timer, args = arguments, start; return function loop() { let self = this; let now = Date.now(); if (!start) { start = now; } if (timer) { clearTimeout(timer); } if (now - start >= mustRunDelay) { method.apply(self, args); start = now; } else { timer = setTimeout(function () { loop.apply(self, args); }, 50); } } } /** * 鍥炲埌椤堕儴鍑芥暟 * @param $el jq鍏冪礌 * @param t 鏄剧ず闅愯棌杩囨浮鏃堕棿,榛樿300 */ function toTop(el, t) { if(t == undefined) t = 300; window.onscroll = throttle(function () { var scrollTop = document.body.scrollTop || document.documentElement.scrollTop; var $el = $(el); if (scrollTop >= 50) { $el.fadeIn(300); } else { $el.fadeOut(300); } }, 600); $(el).click(function () { var $that = $(this); $('html,body').animate({ 'scrollTop': 0 }, 500, function () { $that.fadeOut(300); }); }); }