多个jQuery-Effects同时并行

时间:2012-02-03 10:58:41

标签: jquery position jquery-animate parallel-processing fade

我想在一个子菜单中淡出并同时获得该位置。

喜欢酷酷的Coda-Tooltip(http://panic.com/coda/)而不是“下载”。

我的代码这次只是褪色:

$(document).ready(function(){
    $('#access').hover(function () {
        $(this).children('ul').fadeIn();
         $(this).children('ul')...position();

    }, function () {
        $(this).children('ul').fadeOut('slow');
        $(this).children('ul')...position();
    });
});

由于 INGO

现在我这样做:

$(document).ready(function(){
$('#access').hover(function () {
    $(this).children('ul').stop().animate({opacity:1, paddingTop:'10px'}, 400);

}, function () {
    $(this).children('ul').stop().animate({opacity:0, paddingTop:'0px'}, 300);
});

});

Fadein和填充效果很好。但不是由fadeOut。我的错误是什么?

2 个答案:

答案 0 :(得分:2)

我能想到的最好的方法是使用 jQuery swichClass 。它使用animate implicitly

查看这个小提琴示例: http://jsfiddle.net/xyDwV/1/

<强> CSS:

.before{
    background-color : red;
    height : 400px;
    width :200px;
    opacity : 1;
}
.after{
    background-color : blue;
    height : 200px;
    width : 400px;
    opacity : 0.5;
}

<强> jquery的:

$(document).ready(function(){
  $('#mydiv').hover(function () {
        $(this).switchClass('before','after',500);
    }, function () {
        $(this).switchClass('after','before',500);
  });
});

答案 1 :(得分:0)

只需使用animate()滚动自己的动画即可。并且永远不要忘记使用stop来取消当前正在运行的动画。

$(this).find('ul').stop().animate({opacity:1, top:'...', left:'...'});