扫码关注官方订阅号
*{padding:0;margin:0;} .d1{height:50px;width:100%;overflow-y: auto;} .d2{width:1000px;height:100%;background:red;}
如何知道滚动d1,滚动到了尽头呢?
判断: d1.scrollLeft == d1.scrollWidth - d1.clientWidth;
/* *进行滚动条到边界的监听 *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(); } } }); }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
判断: d1.scrollLeft == d1.scrollWidth - d1.clientWidth;