admin管理员组文章数量:1332896
I've created a simple ponent on reactjs
(kind of a value-picker: plunker)
Now, I want the upper and lower parts of the control to be hidden (opacity=0
) and animate to opacity=1
when user hovers the central div
(.range-picker-selection
) with mouse.
Since there's no way I can operate with DOM
directly from functions of my ponent (reactjs
discourages this) I guess I should change the state ( to something like state.expanded = true
) and rely on reactjs
to reflect the change.
But how can I achieve the animation effect?
With jQuery I would have used element.animate({opacity:0})
but now I don't have access to DOM
I've created a simple ponent on reactjs
(kind of a value-picker: plunker)
Now, I want the upper and lower parts of the control to be hidden (opacity=0
) and animate to opacity=1
when user hovers the central div
(.range-picker-selection
) with mouse.
Since there's no way I can operate with DOM
directly from functions of my ponent (reactjs
discourages this) I guess I should change the state ( to something like state.expanded = true
) and rely on reactjs
to reflect the change.
But how can I achieve the animation effect?
With jQuery I would have used element.animate({opacity:0})
but now I don't have access to DOM
1 Answer
Reset to default 8Something like this?
http://plnkr.co/edit/5tLWNTtpsSWBUCgnKwQO?p=preview
I updated the state to have a hovered attribute and two mouse enter / leave methods to set the value which are bound the .range-picker-selection element in the render function
<div className="range-picker-selection" onMouseEnter={this.onMouseEnterHandler} onMouseLeave={this.onMouseLeaveHandler}>
onMouseEnterHandler: function () {
this.setState({
hovered: true
})
},
onMouseLeaveHandler: function () {
this.setState({
hovered: false
})
},
I also updated the render function to set the opacity to 0 or 1 accordingly for the elements.
style={{opacity: this.state.hovered ? 1 : 0}}
Finally, the actual animation is done with CSS animations
transition: opacity 1s;
I hope this helps
本文标签: javascriptReactJS component fadeInfadeOut on mouseentermouseleaveStack Overflow
版权声明:本文标题:javascript - ReactJS component: fadeInfadeOut on mouse-entermouse-leave - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742317080a2452032.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论