var ehang = {}; //loading函数 //arr [要加载的资源地址数组] callback [需要处理的回调函数] ehang.loading = function(arr,callBack){ var startTime = new Date().getTime(); var currentTime = 0; var n = 0; for (var i = 0, len = arr.length; i < len; i++) { var img = new Image; img.src = arr[i]; img.onload = function() { if (n == len-1) { console.log(n); $("#loading").fadeOut(); currentTime = new Date().getTime(); console.log(currentTime-startTime); if( typeof(callBack) == "function"){ callBack(); } } n++; } img.onerror = function() { n++; console.log('资源'+arr[i]+'加载失败了'); } } } //检测当前浏览器是不是IE浏览器 ehang.isIE = function(){ if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0)) { return true; } return false; } //设置cookie ehang.setCookie = function(cname, cvalue, exdays){ var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = "expires="+d.toUTCString(); document.cookie = cname + "=" + cvalue + "; " + expires; } //获取cookie ehang.getCookie = function(name) { var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)) return unescape(arr[2]); else return null; } //清楚cookie ehang.clearCookie = function(name){ setCookie(name, "", -1); } //回到顶部 ehang.goTop = function(){ } //设置语言版本为中文 ehang.langCN = function(){ ehang.setCookie('morenLang', 'cn'); alert(111111); location.reload(); } ehang.langEN = function(){ ehang.setCookie('morenLang', 'en'); location.reload(); } //浏览器语言版本检测 //中文返回1 //英文和其他返回2 ehang.browserLanguage = function(){ var type = navigator.appName; if (type == "Netscape") { var lang = navigator.language; } else { var lang = navigator.userlanguage; } var lang = lang.substr(0, 2); if (lang == "en") { return 2; } else if (lang == "zh") { return 1; } else { return 2; } } //判断是不是edge ehang.browserType = function(){ var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 var isOpera = userAgent.indexOf("OPR") > -1; //是不是欧鹏浏览器 var isChrome = userAgent.indexOf("Chrome") > -1 && userAgent.indexOf("OPR") == -1; //谷歌浏览器 var isSafari = userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Version") > -1; //苹果浏览器 var isFirefox = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器 var isEdge = userAgent.indexOf("Edge") > -1; var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 || userAgent.indexOf("rv:11.0") > -1; //IE7 8 9 10 11 if(isIE){ return "Ie"; var fIEVersion = 0; var reIE = new RegExp("MSIE (\\d+\\.\\d+);"); var reIE11 = new RegExp("rv:(\\d+\\.\\d+)"); if(reIE11.test(userAgent)){ fIEVersion = parseInt(RegExp["$1"]); return fIEVersion; }else{ reIE.test(userAgent); fIEVersion = parseInt(RegExp["$1"]); return fIEVersion; } } if (isFirefox) { return "Firefox"; } if (isOpera) { return "Opera"; } if (isSafari) { return "Safari"; } if (isChrome) { return "Chrome"; } if (isEdge) { return "Edge"; } } ehang.useragent = function(){ var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 alert(userAgent); document.getElementById("text").innerHTML = userAgent; } //固定二级导航 ehang.fixedSubMeun = function(){ var subMenu = $("#subMenu"); var isFixed = false; $(window).on('scroll', function() { var scrollTop = $(window).scrollTop(); if (!isFixed) { if (scrollTop >= 50) { subMenu.css({ "position": "fixed", "top": 0, 'z-index': 2 }); isFixed = true; } } if (scrollTop < 50) { subMenu.css({ "position": "absoulte", "top": 50 }); isFixed = false; } }); } //产品概览页面中,四个等分视频播放 ehang.slideMenu=function(){ var sp,st,t,m,sa,l,w,gw,ot; return{ destruct:function(){ if(m){ clearInterval(m.htimer); clearInterval(m.timer); } }, build:function(sm,sw,mt,s,sl,h){ sp=s; st=sw; t=mt; m=document.getElementById(sm); sa=m.getElementsByTagName('li'); l=sa.length; w=m.offsetWidth; gw=w/l; ot=Math.floor((w-st)/(l-1)); var i=0; for(i;igw && c)){ var owt=0; var i=0; for(i;i0)?oi:1; o.style.width=(ow+oi)+'px'; //console.log(o); //console.log(o.style.width); }else if(ow>ot && !c){ oi=Math.floor((ow-ot)/sp); oi=(oi>0)?oi:1; o.style.width=(ow-oi)+'px'; //console.log(o); //console.log(o.style.width); } if(c){ owt=owt+(ow+oi) }else{ owt=owt+(ow-oi) } } } s.style.width=(w-owt)+'px'; }else{ if(m.htimer) clearInterval(m.htimer) if(m.timer) clearInterval(m.timer); } } }; }();