我正在从 jQuery 2.0.3 切换到 2.1.0。
我注意到在 v2.1.0 中,css transition
直接设置 css 属性时会忽略该属性
$('#someElement').css('width','100px');
在v2.0.3中,我的元素将保持它的css
过渡,而在v2.1.0中我失去了它。
我想知道为什么会有不同的处理方式,以及如何“打开”过渡效果。
使用 jQuery 2.0.3,csstransition
属性生效
$(function() {
$('.myClass').css('width', '100px');
});
.myClass {
height: 50px;
width: 300px;
background-color: red;
transition: width 3s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<div class="myClass"></div>
在 jQuery 2.1.0 中,csstransition
属性被忽略
$(function() {
$('.myClass').css('width', '100px');
});
.myClass {
height: 50px;
width: 300px;
background-color: red;
transition: width 3s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="myClass"></div>
编辑:
我在 Chrome 版本 47.0.2526.106 m 中看到了这种奇怪的行为
在 Firefox 42.0 中,两者都可以正确设置动画