声明btnOne来存储结果 true是到了最左边 false是到了右边
//监听滚动条是否到最右端
scrollListener(){
let parentBox = document.getElementById("scrollBox");//获取滚动区域的dom
let myWidth = parentBox.scrollWidth - parentBox.clientWidth;
//监听滚动
parentBox.addEventListener("scroll",() => {
let needWidth = myWidth - parentBox.scrollLeft;
needWidth = Math.abs(needWidth); //允许误差在5px以内
if (parentBox.scrollLeft >= myWidth || needWidth < 5) {
//滚动到了右边
this.btnOne= false;
}
if (parentBox.scrollLeft == 0) {
//滚动到了左边
this.btnOne= true;
}
},
true
);
};