[英]React Virtual Dom Diff resets Css Animation
I am building a game, with css animations. 我正在用CSS动画制作游戏。
I have this css rule for move animation: 我对移动动画有以下css规则:
.animate {
animation: play-move 1s steps(10) infinite;
}
I update my state every half second so state changes as: 我每半秒更新一次状态,因此状态更改为:
[0, 1, 0]
View: <div/><div class="animate"/><div />
[0, 1, 0]
视图: <div/><div class="animate"/><div />
[0, 0, 1]
View: <div/><div/><div class="animate">
[0, 0, 1]
视图: <div/><div/><div class="animate">
The problem is as the dom changes, the css animation resets, so I can't see the full animation. 问题是随着dom的变化,css动画重置,所以我看不到完整的动画。
see react version: 查看反应版本:
http://jsfiddle.net/CGmCe/12998/ http://jsfiddle.net/CGmCe/12998/
However if you reverse the move direction, animation doesn't reset. 但是,如果您反转移动方向,动画不会重置。
mithriljs version: http://jsfiddle.net/CGmCe/12982/ mithriljs版本: http : //jsfiddle.net/CGmCe/12982/
jquery: http://jsfiddle.net/CGmCe/12968/ jQuery: http : //jsfiddle.net/CGmCe/12968/
instead of updating entire DOM
you can just change class
attr value as like fuddle link below. 您无需更改整个
DOM
,只需更改class
attr值,如下面的fuddle链接。
http://jsfiddle.net/CGmCe/12974/ http://jsfiddle.net/CGmCe/12974/
on render: you can render <div class="tile temp100"></div>
. 在渲染时:您可以渲染
<div class="tile temp100"></div>
。
on state change you can change the class as sequence as temp100,temp010,temp001
在状态更改时,您可以将类别更改为
temp100,temp010,temp001
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.