<div class="d1">
<div class="d2">
</div>
</div>
*{padding:0;margin:0;}
.d1{height:50px;width:100%;overflow-y: auto;}
.d2{width:1000px;height:100%;background:red;}
如何知道滚动d1,滚动到了尽头呢?
/*
*进行滚动条到边界的监听
*ele为要监听的元素
*Option对配置函数
*/
function listenScrollToEnd(ele, option) {
ele.addEventListener('scroll', function(e) {
if(this.scrollWidth !== this.offsetWidth){
if (this.scrollLeft === this.scrollWidth - this.offsetWidth) {
if(typeof option.toRight) option.toRight();
}
if (this.scrollLeft === 0) {
if(typeof option.toLeft) option.toLeft();
}
}
if(this.scrollHeight !== this.offsetHeight){
if (this.scrollTop === this.scrollHeight - this.offsetHeight) {
if(typeof option.toBottom) option.toBottom();
}
if (this.scrollTop === 0) {
if(typeof option.toTop) option.toTop();
}
}
});
}
判断: d1.scrollLeft == d1.scrollWidth - d1.clientWidth;