0

我想希望我的代码能说明一切。

当我将鼠标悬停在一个元素上时,我想在同一类的所有元素上运行每个函数,但不是当前悬停的元素:

$(document).on({
mouseenter: function () {
    $('#%id% .imageStyle').each(function(){
        if($(this) != $(this)){ // obviously this line is incorrect
        // I only want to execute this if the current each iteration is not the element I am hovering over
            $.this.pixastic("desaturate");
        }
    });
    Pixastic.revert(this);
},

mouseleave: function () {
    $(this).pixastic("desaturate");
}
}, '#%id% .imageStyle');

更新,这个新代码做我现在想要的......

$(".%id%desaturate img").addClass("sprightly");


$(document).on({
mouseenter: function () {
    $('.sprightly').not(this).each(function(){
        if($(this).is("img")){
            $(this).trigger("mouseleave");
        }
    });
    Pixastic.revert(this);
},

mouseleave: function () {
    $(this).pixastic("desaturate");
}
}, '#%id% .imageStyle');
4

1 回答 1

2

更新

不需要使用 each 函数,因为.pixastic()它将应用于选择器匹配的所有元素。试试这个,我没有测试过

$("#container").on({
mouseenter: function () {
    $('#container .imageStyle').not(this).pixastic("desaturate");
    Pixastic.revert(this);
},

mouseleave: function () {
    $(this).pixastic("desaturate");
}
}, '.imageStyle');
于 2013-03-09T11:40:03.883 回答