2012-02-03 64 views
3

我想淡入一个子菜单中,并且同时处理位置。同时并行多个jQuery-Effects效果

喜欢酷的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(); 
    }); 
}); 

感谢 英戈

现在我这样做:

$(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。我的错误是什么?

+0

什么是你的问题? – 2012-02-03 11:00:51

+0

并行动画的这个答案http://stackoverflow.com/questions/811750/how-can-i-get-jquery-to-execute-animations-in-exact-parallel – 2012-02-03 11:03:10

+0

检查我的答案中的例子..我有一直在使用它,并非常喜欢它。 – 2012-02-03 12:21:17

回答

0

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

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

非常感谢罗马人。我尝试了一些...请参阅我编辑的问题。 – ogni 2012-02-03 12:47:48

2

我能想到的最好的是利用jQuery swichClass。它使用animateimplicitly

退房这个提琴例如: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); 
    }); 
});