【发布时间】:2014-06-29 03:35:45
【问题描述】:
我正在构建一个 AngularJS 应用程序,它通过转换元素的不透明度来显示和隐藏元素。该元素也通过应用 CSS 关键帧动画进行旋转。我遇到的问题是过渡或动画卡顿。
当元素的不透明度为 1 并且过渡将其淡出为 0 时,该元素似乎向后退了几帧。这在 GIF 中得到了更好的展示。您可以看到它在不透明度更改之前跳回。
这是我的 CSS。
.square {
width: 100px;
height: 100px;
margin: 50px;
background: black;
}
.appear.ng-hide-add {
-webkit-transition: opacity 300ms linear;
opacity: 1;
}
.appear.ng-hide-add.ng-hide-add-active {
opacity: 0;
}
.appear.ng-hide-remove {
-webkit-transition: opacity 300ms linear;
opacity: 0;
}
.appear.ng-hide-remove.ng-hide-remove-active {
opacity: 1;
}
@-webkit-keyframes rotate {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
.rotate {
-webkit-animation: rotate 1.5s infinite linear;
}
这是我的 HTML。
<div ng-app="app" ng-init="show = true">
<p>Toggle the opacity of the square. Sometimes the rotation is interrupted when the opacity transitions from 1 to 0.</p>
<button ng-click="show =!show">Toggle</button>
<div class="square appear rotate" ng-show="show"></div>
</div>
你可以在这个codepen 中玩所有的东西。希望有人能指出我正确的方向。
【问题讨论】:
-
我试过(我相信你也做过)将正方形包裹在另一个元素中并隐藏/显示包装,但它似乎没有帮助:codepen.io/anon/pen/DctGj
-
是的,这对我也不起作用。结束了你的答案。 stackoverflow.com/a/24474564/106997
标签: css angularjs transform transition