2014-11-23 37 views
3

我有一個CSS樣式屬性的div。動畫div的寬度返回錯誤的值

我改變使用JQuery的div的寬度,然後取寬度,但它給出了舊的寬度。

http://jsfiddle.net/zbou654e/1/

<div id="box"></div> 

#box{ 
background-color:red; 
width:200px; 
height:200px; 
-webkit-transition-duration: 0.2s; 
-moz-transition-duration: 0.2s; 
-ms-transition-duration: 0.2s; 
-o-transition-duration: 0.2s; 
transition-duration: 0.2s; 

-webkit-transition-property: height, width; 
-moz-transition-property: height, width; 
-ms-transition-property: height, width; 
-o-transition-property: height, width; 
transition-property: height, width; 
} 


$(document).ready(function(){ 
$('#box').css("width","400px") ; 
console.log($('#box').width()); 
}); 

它給寬度200.Actual值是400

我想是因爲CSS過渡property..How的解決呢?

+0

的問題是,你登錄框的寬度的過渡之前結束。 – 2014-11-23 14:33:07

回答

2

繼剪斷幫助你或你可以檢查FiddleJS

$(document).ready(function() { 
    $('#box').css("width", "400px"); 
    $("#box").on('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd', function() { 

     console.log($('#box').width()); 
    });  
}); 
+0

謝謝你kuldip – 2014-11-23 14:34:00

+0

歡迎,@VirenderSehwag,如果您接受答案請標記爲完整,因此無需進一步的答覆。我也獲得了聲望點。 thnx – kuldipem 2014-11-23 16:06:03

+0

thnx @VirenderSehwag。 – kuldipem 2014-11-25 11:00:03