简体   繁体   English

什么时候以及如何调用寻找页面滚动动作的javascript函数?

[英]When and how to call a javascript function which looks for page scrolling action?

I have written a code to look for page scrolling. 我已经编写了代码来查找页面滚动。 It works when I put it inside script tag. 当我将其放入script标签时,它可以工作。 How to put this code inside a function and let it look for page scrolls? 如何将此代码放入函数中并让其查找页面滚动?

Here is my code 这是我的代码

$(window).scroll(function(){
                if  ($(window).scrollTop() == $(document).height() - $(window).height()){
                    alert('scrolling');
                }
}); 

I did not understand exactly what you ask,something like this ? 我不完全了解您的要求,像这样吗? (put this in a script tag or an external js file) (将其放入脚本标签或外部js文件中)

$(document).ready(function() {

    $(window).scroll(function(e){
         detect_scrollPage(e);
    });

});

function detect_scrollPage(event){
   ...
} 

What about this: 那这个呢:

function scrollBinder(selector, callback){
    $(selector).scroll(function(e){
         callback.call(this, e);
    });
}

$(document).ready(function() {

    scrollBinder('#some_div', function(div, event) {
        //do calcl here
    })

    //or on window
    scrollBinder(window, function(div, event) {
        //do calcl here
    })

});

Any way it is a shorthand, most people will do that the same as you did. 无论是哪种速记方式,大多数人都会像您一样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用javascript操作调用页面? - how to call a page with javascript action? 如何在动态操作中调用外部 Javascript 函数? - How to call an external Javascript function in a dynamic action? 如何使用Jquery在Javascript中加载页面时调用函数 - How to call a function when a page loads in Javascript with Jquery Javascript当我们在Chrome中选择Stay on Page时,如何调用函数 - Javascript How to call a function when we choose Stay on Page in Chrome 当webview页面不同时,如何从java调用javascript函数 - How to call javascript function from java when webview page is different 页面中发生事件时如何调用javascript函数? - How to Call a javascript function when an event occurs in a page ? 如何在contentplaceholder的子页面的页面加载事件中调用javascript函数? - How to call javascript function on the page load event of the child page which is in contentplaceholder? 调用JavaScript函数时,如何阻止网页滚动到顶部? - How do I stop a web page from scrolling to the top when calling a JavaScript function? 用户离开页面时拨打 JavaScript function - Call a JavaScript function when user leaves a page 如何在页面加载事件中调用JavaScript函数? - How to call a JavaScript function on page load event?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM