![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
js小技巧
2021烟花
一段风,一段雨。
展开
-
js数组切割处理
数组切割把一个数组切分成几个数量相同小的数组。// arr: 需要处理的数组// n: 需要分成几个数组function sliceArray(arr, n) { let num = n*1 || 1; let ret = []; arr.forEach((item, index) => { if(index % num === 0) { ret.push([]) } ret[ret.length-1].push(item) }) return ret}数组原创 2020-08-27 17:39:58 · 2221 阅读 · 0 评论 -
项目小技巧
解决场景:当一行文本不知道他的宽度,如果超出了容器的宽度需要设置成超出文本隐藏,没有超出,则不需要设置文本隐藏。 const textDesc = document.querySelector('.txt'); const clientWidth = textDesc.clientWidth; const scrollWidth = textDesc.scrollWidth; // 如果大于则需要超出隐藏 const isEllpise = scrollWidth > clientWi原创 2020-08-18 16:51:24 · 104 阅读 · 0 评论