//获取滚动的坐标exportconstgetScrollPosition=(el = window)=>({x: el.pageXOffset !==undefined? el.pageXOffset : el.scrollLeft,y: el.pageYOffset !==undefined? el.pageYOffset : el.scrollTop
});//滚动到顶部exportconstscrollToTop=()=>{const c = document.documentElement.scrollTop || document.body.scrollTop;if(c >0){
window.requestAnimationFrame(scrollToTop);
window.scrollTo(0, c - c /8);}}//el是否在视口范围内exportconstelementIsVisibleInViewport=(el, partiallyVisible =false)=>{const{ top, left, bottom, right }= el.getBoundingClientRect();const{ innerHeight, innerWidth }= window;return partiallyVisible
?((top >0&& top < innerHeight)||(bottom >0&& bottom < innerHeight))&&((left >0&& left < innerWidth)||(right >0&& right < innerWidth)): top >=0&& left >=0&& bottom <= innerHeight && right <= innerWidth;}
判断终端
exportconst ua = navigator.userAgent.toLowerCase();//19.是否是微信浏览器exportconstisWeiXin=()=>{return ua.match(/microMessenger/i)=='micromessenger'}//20.是否是移动端exportconstisDeviceMobile=()=>{return/android|webos|iphone|ipod|balckberry/i.test(ua)}//21.是否是QQ浏览器exportconstisQQBrowser=()=>{return!!ua.match(/mqqbrowser|qzone|qqbrowser|qbwebviewtype/i)}//22.是否是爬虫exportconstisSpider=()=>{return/adsbot|googlebot|bingbot|msnbot|yandexbot|baidubot|robot|careerbot|seznambot|bot|baiduspider|jikespider|symantecspider|scannerlwebcrawler|crawler|360spider|sosospider|sogou web sprider|sogou orion spider/.test(ua)}//23.是否iosexportconstisIos=()=>{var u = navigator.userAgent;if(u.indexOf('Android')>-1|| u.indexOf('Linux')>-1){//安卓手机returnfalse}elseif(u.indexOf('iPhone')>-1){//苹果手机returntrue}elseif(u.indexOf('iPad')>-1){//iPadreturnfalse}elseif(u.indexOf('Windows Phone')>-1){//winphone手机returnfalse}else{returnfalse}}//24.是否为PC端exportconstisPC=()=>{var userAgentInfo = navigator.userAgent;var Agents =["Android","iPhone","SymbianOS","Windows Phone","iPad","iPod"];var flag =true;for(var v =0; v < Agents.length; v++){if(userAgentInfo.indexOf(Agents[v])>0){
flag =false;break;}}return flag;}