jquery:检测滚动位置 [英] jquery : detecting scroll position

查看:124
本文介绍了jquery:检测滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在滚动时看到我的页脚来查看。

I want to get an alert when, while scrolling, my footer comes to view.

$(window).on("mousewheel", function(){
    if ($(window).scrollTop() + $(window).height() > $('#footer').position().top){    
        alert("footer visible");
    }  
    else{
        alert("footer invisible");  
    }
});

http://jsfiddle.net/JRUnr/10/

所有带高度的条件似乎都是正确的,但在滚动期间不会。

All conditions with height seem right, but not during scrolling.

推荐答案

工作 DEMO



试试这个

Working DEMO

Try this

$(window).scroll(function () {

    if ($(window).scrollTop() + $(window).height() > $('.footer').offset().top) {
        alert("footer visible");
    } else {
        alert("footer invisible");
    }
});

希望这会有所帮助,谢谢

Hope this helps,Thank you

这篇关于jquery:检测滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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