yoda
yoda

Reputation: 10981

passing function argument to another function

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);
    });
});

Upvotes: 0

Views: 104

Answers (2)

Lloyd Banks
Lloyd Banks

Reputation: 36638

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);
    });
});

Upvotes: 1

net.uk.sweet
net.uk.sweet

Reputation: 12431

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);
    });
});

Upvotes: 2

Related Questions