jQuery查找水平滚动的结尾 [英] Jquery-find the end of horizontal scroll

查看:65
本文介绍了jQuery查找水平滚动的结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div框,其中有溢出-x:scroll,当用户到达滚动末尾时,我想发出alert()消息.
不幸的是,我不能像垂直滚动一样使用文档高度并找到用户何时在页面底部,所以我不知道是否有可能.我试图将div.scrollLeft()与div.width进行比较,但div的宽度是恒定的,并且
所以,即使滚动随时间变化,也知道如何知道滚动的结尾吗?
谢谢.

I have a div box where i have overflow-x:scroll and i want to alert() a message when user reach the end of the scroll.
Unfortunately i can't use document height like with the vertical scroll and find when user is at the bottom of the page,so i can't figure out if it's even possible to do.I have tried to compare the div.scrollLeft() with div.width but the width of the div is constant and it's not working.
So any idea how to know the end of the scroll even if the scroll changes with time?
Thanks.

推荐答案

html

<div style="width: 4000px">Scroll down!</div>

jquery

 var scrolLeft = $(window).scrollLeft();
 var windw = $(window).width();//important
 var documet = $(document).width();
    $(window).scroll(function() {
        if($(window).scrollLeft() + windw == documet){
            console.log("right!");
        }
    });

另一个

<div id="scroll">
    <div id="width" style="width: 4000px">Scroll down!</div>
</div>

css

#scroll{
    width:200px;
    height:100px;
    background-color:red;
    overflow:auto;
}

jquery

var scrolLeft = $(window).scrollLeft();
var windw = $('#scroll').width();//important
var documet = $('#width').width();
    $('#scroll').scroll(function() {
        if($('#scroll').scrollLeft() + windw == documet){
            console.log("right!");
        }
    });

这篇关于jQuery查找水平滚动的结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆