function secshow() { var windowheight = $(window).height(); $('.showani').each(function() { if ($(window).scrollTop() + windowheight * 0.9 > $(this).offset().top) { $(this).addClass('actived'); } }); }; function fontsize() { var windowwidth = window.innerWidth; if (windowwidth <= 1024) { var size = windowwidth * 16 / 375; $('html').css('font-size', size + 'px'); } else { $('html').removeAttr('style'); } }; function headerscroll() { // 确定上下滚动 var p = 0, t = 0; $(window).scroll(function(e) { p = $(this).scrollTop(); if (t < p && p > 0) { //下滚 $('#header').addClass('hide'); } else { //上滚 $('#header').removeClass('hide'); } setTimeout(function() { t = p; }, 0); }); }; function DevicePixelRatio() { function constructor() { //this.flag = false; } //获取系统类型 function getSystem() { let flag = false; var agent = navigator.userAgent.toLowerCase(); // var isMac = /macintosh|mac os x/i.test(navigator.userAgent); // if(isMac) { // return false; // } //现只针对windows处理,其它系统暂无该情况,如有,继续在此添加 if (agent.indexOf("windows") >= 0) { return true; } } //获取页面缩放比例 // _getDevicePixelRatio() { // let t = this; // } //监听方法兼容写法 function addHandler(element, type, handler) { if (element.addEventListener) { element.addEventListener(type, handler, false); } else if (element.attachEvent) { element.attachEvent("on" + type, handler); } else { element["on" + type] = handler; } } //校正浏览器缩放比例 function correct() { let t = this; //页面devicePixelRatio(设备像素比例)变化后,计算页面body标签zoom修改其大小,来抵消devicePixelRatio带来的变化。 document.getElementsByTagName('body')[0].style.zoom = 1 / window.devicePixelRatio; } //监听页面缩放 function watch() { let t = this; addHandler(window, 'resize', function() { //注意这个方法是解决全局有两个window.resize //重新校正 correct(t) }) } //初始化页面比例 function init() { let t = this; if (getSystem(t)) { //判断设备,目前只在windows系统下校正浏览器缩放比例 //初始化页面校正浏览器缩放比例 correct(t); //开启监听页面缩放 watch(t); } } init(); }; // 禁止通过 ctrl + +/- 和 ctrl + 滚轮 对页面进行缩放 document.addEventListener('keydown', function (event) { if ((event.ctrlKey === true || event.metaKey === true) && (event.which === 61 || event.which === 107 || event.which === 173 || event.which === 109 || event.which === 187 || event.which === 189)) { event.preventDefault() } }, false) // Chrome IE 360 window.addEventListener('mousewheel', function (event) { if (event.ctrlKey === true || event.metaKey) { event.preventDefault() } }, { passive: false }) // firefox window.addEventListener('DOMMouseScroll', function (event) { if (event.ctrlKey === true || event.metaKey) { event.preventDefault() } }, { passive: false }) function isIE() { if(!!window.ActiveXObject || "ActiveXObject" in window) { $('html').addClass('ie'); } } $(function() { isIE(); // $('html').attr({ // "unselectable": "on", // "onselectstart": "return false;" // }); headerscroll(); fontsize(); $(window).load(function() { secshow(); }); $(window).scroll(function() { secshow(); if ($(window).scrollTop() > 0) { $('#header').addClass('fixed'); } else { $('#header').removeClass('fixed'); } }); $(window).resize(function() { secshow(); fontsize(); headerscroll(); }); // sidenav 打开 $('#header .menu').click(function() { $('#sidenav').addClass('active'); }); // sidenav 关闭 $('#sidenav .close').click(function() { $('#sidenav').removeClass('active'); }); // sidenav 副导航 $('#sidenav .middle-part .level1').click(function() { $(this).parents('.box').toggleClass('active'); }); $('#header .language-box a').click(function() { console.log(1); if($(this).html()=="EN"){ window.location="/en/index.shtml" } }); // header搜索按钮 $('#header .search-box .btns').click(function() { if ($(this).parents('.search-box').hasClass('active')) { if ($(this).siblings('input').val() == "") { $(this).parents('.search-box').removeClass('active'); } else { location.href = './search_result.shtml?searchValue='+$(this).siblings('input').val(); } } else { $(this).parents('.search-box').addClass('active'); } }); // header搜索回车 $('#header .search-box input').keydown(function(event) { if ($(this).parents('.search-box').hasClass('active')) { if (event.which == 13 && $(this).val() != '') { location.href = './search_result.shtml?searchValue='+$(this).val(); } } }); $('#sidenav .search-box input').keydown(function(event) { if (event.which == 13) { if ($(this).val() != '') { location.href = './search_result.shtml?searchValue='+$(this).val(); } else{ alert('请输入关键词搜索'); } } }); $('#sidenav .search-box .btns').click(function() { if ($(this).siblings('input').val() == "") { alert('请输入关键词搜索'); } else { location.href = './search_result.shtml?searchValue='+ $(this).siblings('input').val(); } }); }); /** * 时间验证 * value 需要验证的日期 */ function isDateTime(value) { //debugger //let reg = /^[0-9]{4}[-./]([1-9]|0[1-9]|1[0-2])[-./]([1-9]|0[1-9]|[1-2][0-9]|3[0-1])$/; let reg = /^[0-9]{4}-([1-9]|0[1-9]|1[0-2])-([1-9]|0[1-9]|[1-2][0-9]|3[0-1])$/; if (!reg.test(value)) { return false; } let arr = value.split('-'); let year = parseInt(arr[0]); let month = parseInt(arr[1]); let day = parseInt(arr[2]); //验证31 if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month ==10 || month == 12){ console.log("====") }else if(month == 4 || month == 6 || month == 9 || month == 11){ if(day > 30){ return false; } }else if(month == 2){ // 能被400整除,或者能被4整除但不能被100整除的都是闰年,其余的年份均为平年 if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) { if (day > 29) { return false; } } else { // 平年的2月只有28号 if (day > 28) { return false; } } } return true; } // 验证邮箱的规则 function checkEmail ( value) { // 验证邮箱的正则表达式 const regEmail = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/ if (regEmail.test(value)) { // 合法邮箱 return '' } return "请输入合法的邮箱"; } // 验证手机号的规则 function checkMobile ( value) { // 验证手机号的正则表达式 const regMobile =/^1((3[\d])|(4[5,6,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[1-3,5-8])|(9[1,8,9]))\d{8}$/ if (regMobile.test(value)) { return ''; } return '请输入合法的手机号'; } /** * @desc 用于微信内调整字体大小的控制方法, 将字体设为默认并重写事件 * @author jealyn * @date 2021-02-18 15:29:54 * @version V1.0.0 */ (function() { if (typeof WeixinJSBridge == 'object' && typeof WeixinJSBridge.invoke == 'function') { handleFontSize(); } else { document.addEventListener('WeixinJSBridgeReady', handleFontSize, false); } function handleFontSize() { // 设置网页字体为默认大小 WeixinJSBridge.invoke('setFontSizeCallback', { fontSize: 0 }); // 重写设置网页字体大小的事件, // 将字体大小设为默认 WeixinJSBridge.on('menu:setfont', function() { WeixinJSBridge.invoke('setFontSizeCallback', { fontSize: 0 }); }); } })();