Animated div width returns wrong value

I have a div property with CSS.

I am changing the width of a div using JQuery. Then we take the width, but it gives the old width.

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());
});

      

it gives a width of 200. The active value is 400

I think it is because of the css transition property. How to solve it?

+3


source to share


1 answer


After trimmed help, you or you can check FiddleJS



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

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

      

+2


source







All Articles