toos
Posted chefweb
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了toos相关的知识,希望对你有一定的参考价值。
/* ------------------------------------------------------ | | 增加 删除 检查 元素的class | elem 需要操作的元素 cls class | ------------------------------------------------------ */ // 检查 export const hasClass = (elem, cls) =>{ cls = cls || ‘‘ if (cls.replace(/s/g, ‘‘).length === 0) return false return new RegExp(‘ ‘ + cls + ‘ ‘).test(‘ ‘ + elem.className + ‘ ‘) } // 增加 export const addClass = (elem, cls) => { if (!hasClass(elem, cls)) { elem.className = elem.className === ‘‘ ? cls : elem.className + ‘ ‘ + cls } } // 删除 export const removeClass = (elem, cls) =>{ if (hasClass(elem, cls)) { var newClass = ‘ ‘ + elem.className.replace(/[ ]/g, ‘‘) + ‘ ‘ while (newClass.indexOf(‘ ‘ + cls + ‘ ‘) >= 0) { newClass = newClass.replace(‘ ‘ + cls + ‘ ‘, ‘ ‘) } elem.className = newClass.replace(/^s+|s+$/g, ‘‘) } } /* ------------------------------------------------------ | | 注册事件 | obj 事件元素 type 事件类型 fn触发函数 | ------------------------------------------------------ */ export const addEvent = (obj,type,fn) =>{ if(obj.attachEvent){ //ie obj.attachEvent(‘on‘+type,() => { fn.call(obj); }) }else{ obj.addEventListener(type,fn,false); } } /* ----------------------------------------------------- | | 获取滚动条距离浏览器顶部的距离 | ----------------------------------------------------- */ export const getScrollTop = () => { let scrollPos; if (window.pageYOffset) { scrollPos = window.pageYOffset }else if (document.compatMode && document.compatMode !== ‘BackCompat‘){ scrollPos = document.documentElement.scrollTop }else if (document.body) { scrollPos = document.body.scrollTop } return scrollPos } /* ----------------------------------------------------- | | 获取body的高度 | ----------------------------------------------------- */ export const getBodyHeight = () => { return document.documentElement.clientHeight || document.body.clientHeight || window.clientHeight }
以上是关于toos的主要内容,如果未能解决你的问题,请参考以下文章
带有片段的 Android Studio 导航抽屉。工具栏隐藏在下一个片段活动或页面中
jeesite表字段太多导致不能自动生成那张表的代码——————jetty 之 form too large | form too many keys 异常
如何处理 R0915: Too many statements (69/50) (too-many-statements) in pylint?
蓝牙 (BLE) bluetoothLeAdvertiser.startAdvertising 引发错误代码 2 (ADVERTISE_FAILED_TOO_MANY_ADVERTISERS)