0

In the following piece of code, I want to pass delta argument into the function being called by fadeOut, without having to set a variable outside the scope of those functions. Is it possible?

$(window).bind('mousewheel', function(event, delta, deltaX, deltaY) {
    $('#view img').fadeOut('slow', function() {
        $('.view-loading').fadeIn('fast');
        showcase.rotate(delta);
    });
});
3
  • 3
    Isn't the variable delta already available to the inner function via the closure in your example? Commented Oct 8, 2013 at 23:58
  • 2
    you have it accessible in the scope so what is the point of providing argument to your callback? Commented Oct 8, 2013 at 23:59
  • @SeanVieira no, I get undefined. Commented Oct 9, 2013 at 0:29

2 Answers 2

2

I can't really work out what the deal is with jQuery and mousewheel (it's late, I'm tired), but using jQuery 1.9.1, I can get a delta from the originalEvent property of the event object (which is in scope within your inner function. (fiddle).

$(window).bind('mousewheel', function(event) {
    $('#view img').fadeOut('slow', function() {
        $('.view-loading').fadeIn('fast');
        showcase.rotate(event.originalEvent.deltaY);
    });
});
Sign up to request clarification or add additional context in comments.

Comments

1

You have to manually define the delta with the jQuery "mousewheel" event

$(window).bind('mousewheel', function(event) {
    event = event.originalEvent;
    var delta = event.wheelDelta;
    $("#view img").fadeOut('slow', function() {
        $('.view-loading').fadeIn('fast');
        showcase.rotate(delta);
        showcase.fillRect(100, 10, 150, 100);
    });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.