2015-04-06 135 views
0

所以我有这样的代码淡入淡出相关的div动画

$(function() { 
$(".one, .two, .three").click(function (event) { 
    event.preventDefault(); 
    $("#" + $(this).attr("class")).fadeIn().siblings('.popup').hide(); 
    return false; 
}); 
$(".close").click(function (event) { 
    event.preventDefault(); 
    $(".popup").fadeOut(); 
}); 
}); 

但我不太知道如何制作动画。我想要做的是当你点击一个链接时,div淡入(它有效),但是当你点击相关链接时,我不希望盒子淡出并再次(除了它里面的文本)。

这里的fiddle

谢谢! X

+1

使用包装对于所有的弹出窗口并淡入其中。类似于[this](http://jsfiddle.net/qepk0auL/3/) – anpsmn 2015-04-06 06:13:46

+0

您只需更改'fadeOut()'而不是'hide()' – Logz 2015-04-06 06:20:27

回答

0

为了得到这个褪色正确两种方式我认为你需要用z-index的发挥:

$(function() { 

$(".one, .two, .three").click(function (event) { 
    event.preventDefault(); 
    $("#" + $(this).attr("class")).css('z-index', 1).fadeIn(function(){ 
     $(this).css('z-index', 0).siblings('.popup').hide();   
    }); 
    return false; 
}); 


$(".close").click(function (event) { 
    event.preventDefault(); 
    $(".popup").fadeOut(); 
}); 
}); 

这里是fiddle

+0

哇,这实际上相当惊人!直到现在,我没有注意到另一个上的错误。非常感谢! – Ely 2015-04-06 14:42:18

1

希望这对你的作品

$(函数(){

$(".one, .two, .three").click(function (event) { 
    event.preventDefault(); 
    $("#" + $(this).attr("class")).fadeIn(function(){ 
     $(this).siblings('.popup').hide();   
    }); 
    return false; 
}); 


$(".close").click(function (event) { 
    event.preventDefault(); 
    $(".popup").fadeOut(); 
}); 

});

这里是更新fiddle

+0

哇。谢谢!这是完美的。 :D – Ely 2015-04-06 07:00:12