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 0
Add a ment  | 

3 Answers 3

Reset to default 4

Well, 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