I'm trying to make a small animation on HTML element when data values stored in state change. How can achieve that?
How can I add a CSS class to ponent in ponentWillUpdate
and remove it in ponentDidUpdate
? I don't see any reference to any HTML element there.
I'm trying to make a small animation on HTML element when data values stored in state change. How can achieve that?
How can I add a CSS class to ponent in ponentWillUpdate
and remove it in ponentDidUpdate
? I don't see any reference to any HTML element there.
- I remend to read facebook.github.io/react/docs/animation.html – Felix Kling Commented Jun 10, 2015 at 18:42
- Or you could also simply search: stackoverflow./search?q=%5Breactjs%5D+animation – Felix Kling Commented Jun 10, 2015 at 18:55
- I tried, but I used wrong keywords. I got only a couple of results. – sunpietro Commented Jun 10, 2015 at 21:03
1 Answer
Reset to default 4If you need to add a class to a ponent: React.findDOMNode(this).classList.add("classname");
To remove:
React.findDOMNode(this).classList.remove("classname");
If you're trying to add a class in ponentWillUpdate
and remove it in ponentDidUpdate
, you'd need to use something like a setTimeout to notice a change. For example:
ponentWillUpdate: function() {
React.findDOMNode(this).classList.add("class1", "class2");
},
ponentDidUpdate: function() {
var el = React.findDOMNode(this);
setTimeout(function(){
el.classList.remove("class1");
}, 1000);
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745300254a4621392.html
评论列表(0条)