0

うまくいけば、私のコードがそれ自体を物語っていると思います。

要素にカーソルを合わせると、現在ホバーされている要素ではなく、同じクラスのすべての要素に対して each 関数を実行したい:

$(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

更新しました

.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 に答える