jQuery 检测“身体”内向下滚动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16837877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:53:29  来源:igfitidea点击:

Detect scroll down inside "body"

jqueryscroll

提问by Kim

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.

我在 Facebook iframe 中有一个应用程序,需要知道用户何时在正文内部向下滚动。我现在拥有的这段代码仅检测整个窗口。但我不能让它工作,所以它在体内燃烧。

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();
    }
});

回答by imbecile

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 :)

我主要将它用于触摸设备,但尝试一下没有坏处:)