let box1 = document.getElementById("box1")
let myWidth = box1.scrollWidth - box1.clientWidth
box1.addEventListener('scroll', () => { //监听滚动
let needWidth = myWidth - box1.scrollLeft
needWidth = Math.abs(needWidth) //允许误差在5px以内
if (box1.scrollLeft >= myWidth || needWidth < 5) {
//滚动到了右边
this.btnOne1 = false
}
if (box1.scrollLeft == 0) {
//滚动到了左边
this.btnOne1 = true
}
}, true)
js判断盒子里面的滚动条是否滚动到盒子的右边界
最新推荐文章于 2023-08-28 09:47:00 发布