Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

width of an animating div return wrong value

Tags:

html

jquery

css

I have a div with css style property.

I change the width of div using JQuery.then 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 width as 200.Actual value is 400

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

like image 723
Virender Sehwag Avatar asked Mar 19 '26 09:03

Virender Sehwag


1 Answers

Following snipped 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());
    });    
});
like image 83
kuldipem Avatar answered Mar 21 '26 21:03

kuldipem