jquery : detecting scroll position

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.

Answers:

Answer

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

Answer

There is a jquery plugin for this task named jQuery Waypoints (http://imakewebthings.com/jquery-waypoints/)

$('#footer').waypoint(function(direction) {
    alert('Top of thing hit top of viewport.');
});
Answer

here is a working fiddle... http://jsfiddle.net/kasperfish/JRUnr/14/

it is hacked together but it works

        flag=true;


$(window).scroll(function() {
    st=$(window).scrollTop();
    $('#topscroll').html(st)


    if(st>1450){
        if(flag)
        alert('test');flag=false;
    }

});

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.