Reputation: 1156
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();
}
});
Upvotes: 7
Views: 32988
Reputation: 468
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 :)
Upvotes: 5