javascript - 有没有事件可以得到一个横向的滚动条滚动到了底部(尽头)?
巴扎黑
巴扎黑 2017-04-11 11:52:16
[JavaScript讨论组]

*{padding:0;margin:0;} .d1{height:50px;width:100%;overflow-y: auto;} .d2{width:1000px;height:100%;background:red;}

如何知道滚动d1,滚动到了尽头呢?

巴扎黑
巴扎黑

全部回复(2)
天蓬老师

判断: 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中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号