[英]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.