Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect scroll down inside "body"

Tags:

jquery

scroll

I have an app inside a Facebook iframe and need to know when the user is scrolling down, inside the body. This code I have right now is only detecting the whole window. But I can't get it to work so it fires inside the body.

Any ideas how I can modify this?

//lastAddedLiveFunc();
$(window).scroll(function(){

    var wintop = $(window).scrollTop(), docheight = $(document).height(), winheight = $(window).height();
    var  scrolltrigger = 0.95;

    if  ((wintop/(docheight-winheight)) > scrolltrigger) {
     //console.log('scroll bottom');
     lastAddedLiveFunc();
    }
});
like image 695
Kim Avatar asked Aug 09 '26 20:08

Kim


1 Answers

Try this:

$('body').on('scroll', function (e){
    if ($('#selector').has($(e.target)).length){                       
     //do what you want here
    }
});

I use this mostly for touch devices, but no harm in trying it out :)

like image 104
imbecile Avatar answered Aug 11 '26 13:08

imbecile



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!