将函数参数传递给另一个函数

时间:2013-10-08 23:52:17

标签: javascript jquery

在下面的代码中,我想将delta参数传递给fadeOut调用的函数,而不必在这些函数的范围之外设置变量。有可能吗?

$(window).bind('mousewheel', function(event, delta, deltaX, deltaY) {
    $('#view img').fadeOut('slow', function() {
        $('.view-loading').fadeIn('fast');
        showcase.rotate(delta);
    });
});

2 个答案:

答案 0 :(得分:2)

我无法弄清楚jQuery和mousewheel的交易是什么(已经很晚了,我累了),但是使用jQuery 1.9.1,我可以从中获得delta事件对象的originalEvent属性(在您的内部函数范围内。(fiddle)。

$(window).bind('mousewheel', function(event) {
    $('#view img').fadeOut('slow', function() {
        $('.view-loading').fadeIn('fast');
        showcase.rotate(event.originalEvent.deltaY);
    });
});

答案 1 :(得分:1)

您必须使用jQuery“mousewheel”事件

手动定义增量
$(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);
    });
});
相关问题