admin管理员组文章数量:1410689
i was reading those few lines of code from a javascript(Jquery) file and I was wondering where those arguments "x" and "y" are ing from.Is the scroll event that is taking care peraphs?
$(window).scroll(function(x,y) {
dosomething(withThis);
});
thanks Luca
P.S. here is the jquery excerpt that made me ask this question Is this an elegant way to make elements fade in while scrolling?
i was reading those few lines of code from a javascript(Jquery) file and I was wondering where those arguments "x" and "y" are ing from.Is the scroll event that is taking care peraphs?
$(window).scroll(function(x,y) {
dosomething(withThis);
});
thanks Luca
P.S. here is the jquery excerpt that made me ask this question Is this an elegant way to make elements fade in while scrolling?
Share edited May 23, 2017 at 10:34 CommunityBot 11 silver badge asked Dec 4, 2012 at 17:56 lucaluca 37.2k27 gold badges89 silver badges125 bronze badges 03 Answers
Reset to default 4Well, open Firebug console (or web dev. tools) and paste there this code:
$(window).scroll(function(x,y,z) {
console.log(x,y,z)
});
After execution and scrolling you'll see the result (works on sites with jQuery).
As expected, first argument - event object, 2nd and 3rd - undefined;
But, you can trigger events manually, and pass any arguments.
More info here: http://api.jquery./trigger/
No, the handler for the scroll event takes only an event object, not x,y
. That code is misleading and wrong. We can't help if you don't show the full code.
This is the same thing as if you define a method
function add(a,b) {
return a + b;
}
// When called like this, b will be undefined, as is y in your example
// programmer error not caught by the piler
add(7);
You could inspect the arguments
variable on any function, so you can get an idea of the data that's passed in.
$(window).scroll(function() {
console.log(arguments);
});
本文标签: javascriptJquery(selector)scroll is passing parameters to its callback functionStack Overflow
版权声明:本文标题:javascript - Jquery - $(selector).scroll is passing parameters to its callback function? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745017592a2637937.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论