2012-02-03 65 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); 
    }); 
});