Take the 2-minute tour ×

i was reading those few lines of code from a javascript(Jquery) file and I was wondering where those arguments "x" and "y" are coming from.Is the scroll event that is taking care peraphs?

$(window).scroll(function(x,y) {


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|improve this question
add comment

3 Answers

up vote 3 down vote accepted

Well, open Firebug console (or web dev. tools) and paste there this code:

 $(window).scroll(function(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.com/trigger/

share|improve this answer
the console prints out exactly what you told me: Object {originalEvent=Event scroll, type="scroll", ...},undefined; –  luca Dec 4 '12 at 18:40
I just updated my question with a link .Could you please help me understand the meaning of those arguments? Or is just a syntax error? –  luca Dec 4 '12 at 18:47
Just an error, they aren't used in that script. But again - there are some use cases when you got to pass additional data (arguments) to the event handler. –  Michael Malinovskij Dec 4 '12 at 22:20
add comment

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 compiler
share|improve this answer
add comment

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() {
share|improve this answer
It's a good learning tool, but you should program from the interface (documentation) not from a specific usage, functions can get called from multiple contexts with different parameters –  Juan Mendes Dec 4 '12 at 18:21
Absolutely, that's why I said it's just to get an idea of the data. –  rdiazv Dec 4 '12 at 18:27
add comment

Your Answer


