2012-01-03 50 views
0

我们可以使用透明度,高度,宽度,左侧和顶部与jQuery动画功能一起jQuery的动画功能选项一起

$('#div').animate({ 
opacity : 1, 
height : 300, // You desired height. 
width : 400 
}); 

$('#div').animate({ 
opacity : 1, 
height : 0, 
width : 0 
}); 

如果任何人有任何想法,那么请共享跟我。感谢

+0

发生了什么事,当你尝试过吗? – 2012-01-03 11:20:43

回答

3

是的,你可以将这些属性动画在一起。正如你所写的,你的代码工作得很好,除非你可能不想立即执行另一个。

这里有一个working example

jQuery(function($) { 

    $("#theButton").click(function() { 
    var theDiv = $("#theDiv"); 
    if (theDiv.height() > 0) { 
     theDiv.animate({ 
     opacity : 0, 
     height : 0, 
     width : 0 
     }); 
    } 
    else { 
     theDiv.animate({ 
     opacity : 1, 
     height : 300, // You desired height. 
     width : 400 
     }); 
    } 
    }); 

    function display(msg) { 
    $("<p>").html(msg).appendTo(document.body); 
    } 
}); 

附注:我会强烈劝阻你给一个元素id “分区”。这只是要求混淆。

1

我不明白为什么不能。像这样做:

$(selector).animate({opacity:0,height:'100px',width:'100px',left:'20px',top:'20px'},'slow'); 

例子:http://jsfiddle.net/6HF5z/