jquery - 动画 div 的宽度返回错误值

标签 jquery html css

我有一个带有 css 样式属性的 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,实际值为400

我认为是因为 css transition property..如何解决?

最佳答案

以下片段可以帮助您,或者您可以查看FiddleJS

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

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

关于jquery - 动画 div 的宽度返回错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27089973/

相关文章:

python - 如何删除特定 html 标签内的所有内容(以及标签本身)

html - 如何确保突出显示标题的框不会超出 CSS 屏幕的长度?

asp.net - ajax 选项卡容器 CSS 未正确显示

jquery - 在 jQuery 中选择编号元素范围

javascript - 如何根据点击获取对应对象的值

电子邮件收件箱中未显示 HTML 背景

css - Gwt 应用程序上的 "Sticky"面板

javascript - 淡入淡出

php - 回显包含来自 MySQL 的数据的 HTML(空白)

css - 使用 HTML/CSS 创建直线和圆的交点