jQuery悬停功能

Los*_*Lin 2 jquery hover

嗨我正在尝试创建一个jquery函数,当点击其中一个div时,它会淡化所有其他div.我的代码不起作用,我不确定如何正确编写它.这是我到目前为止:

$("#slider div.popup").hover(
var ind = $(this).index();

$("#slider div.popup").each(function() {
    if ($(this).index() != ind) {
        //fades all other .popup divs
        $(this).animate({
            opacity: 0
        });
    }
}), $("#slider div.popup").each(function() {
    if ($(this).index() != ind) {
        //unfades all other .popup divs
        $('span', this).animate({
            opacity: 1
        });
    }
}

));
Run Code Online (Sandbox Code Playgroud)

这里还有一个例子:http://jsfiddle.net/7j3mk/

有人可以给我指导如何使这段代码工作?

Gab*_*oli 7

除了用于悬停方法的错误语法(它需要两个函数作为参数)您需要使用.not() docs方法

$("#slider div.popup").hover( function(){
    $("#slider div.popup").not(this).stop().animate({
            opacity: 0
        });
}, function(){
    $("#slider div.popup").not(this).stop().animate({
            opacity: 1
        });
});
Run Code Online (Sandbox Code Playgroud)

更新的例子在http://jsfiddle.net/gaby/7j3mk/11/