// 控制根元素字号 (function (doc, win) { var docel = doc.documentelement; var resizeevt = 'orientationchange' in window ? 'orientationchange' : 'resize'; function recalc() { var clientwidth = docel.clientwidth; if (!clientwidth) return; if (clientwidth >= 750) { docel.style.fontsize = '100px'; } else { docel.style.fontsize = 100 * (clientwidth / 750) + 'px'; } }; if (!doc.addeventlistener) return; win.addeventlistener(resizeevt, recalc, false); doc.addeventlistener('domcontentloaded', recalc, false); })(document, window); $(function () { $(document).scroll(function() { var scroh = $(document).scrolltop(); //滚动高度 if(scroh >0){ $('header').addclass('head-active'); }else{ $('header').removeclass('head-active'); } if(scroh > 1000){ $('.btop').css('display','block'); }else{ $('.btop').css('display','none'); } }) // 返回顶部 $(".back-top").click(function () { $('html , body').animate({ scrolltop: 0 }, 'slow'); }) /*锚点动效*/ $('.link-nav a,.link-bg a').click(function() { if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { var $target = $(this.hash); $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']'); if ($target.length) { var targetoffset = $target.offset().top; $('html,body').animate({ scrolltop: targetoffset }, 'slow'); return false; } } }); /*statistics count number*/ statisticscount(); function statisticscount() { if ($('.num .tnumber').length) { console.log(1); $('.num').appear(function() { var count_element = $('.tnumber', this).html(); console.log(count_element); $(".tnumber", this).countto({ from: 0, to: count_element, speed: 2000, refreshinterval: 50, }); }); } } /*click-hamburger*/ // 手机端菜单按钮切换 const headerel = document.queryselector("header"); const burgerel = document.queryselector('.burger'); burgerel.addeventlistener('click',function(){ headerel.classlist.toggle('open') }) var cwidth = document.documentelement.clientwidth; if (cwidth < 678) { // 手机菜单栏切换 $('.nav .item').each(function() { if ($(this).find('.mtwo-menu').length > 0 ) { $(this).find('.mitem').attr('href','javascript:;') $(this).click(function() { $(this).find('.mtwo-menu').css('display','block'); $(this).siblings().find('.mtwo-menu').css('display','none'); }) } }) } else { } //lazyload start(); $(window).on('scroll', function() { start(); }) $('#login,#login1').click(function(evt) { if ($(this).data('url') != '') { $('#login-form').attr('action', $(this).data('url')); } evt = (evt) ? evt : ((window.event) ? window.event : ""); evt.preventdefault(); $('#registerpop').css('display','none'); $('.maskpop,#loginpop').css('display','block'); }) $('#register,#register1').click(function(evt) { evt = (evt) ? evt : ((window.event) ? window.event : ""); evt.preventdefault(); $('#loginpop').css('display','none'); $('.maskpop,#registerpop').css('display','block'); }) $('#lxkf').click(function(evt) { evt = (evt) ? evt : ((window.event) ? window.event : ""); evt.preventdefault(); $('#loginpop,#registerpop').css('display','none'); $('.maskpop,#lxpop').css('display','block'); }) $('.close').click(function(evt) { evt = (evt) ? evt : ((window.event) ? window.event : ""); evt.preventdefault(); cancel(); }) }) function pop(){ $('.maskpop,.pop').css('display','block'); } function cancel() { $('.maskpop,.pop').css('display','none'); } function start() { //.not('[data-isloaded]')选中已加载的图片不需要重新加载 $('img').not('[data-isloaded]').each(function() { var $node = $(this) if(isshow($node)) { loadimg($node) } }) } //判断一个元素是不是出现在窗口(视野) function isshow($node) { return $node.offset().top <= $(window).height() + $(window).scrolltop() } //加载图片 function loadimg($img) { //.attr(值) //.attr(属性名称,值) $img.attr('src', $img.attr('data-src')) //把data-src的值 赋值给src $img.attr('data-isloaded', 1) //已加载的图片做标记 }