Fer*_*o B 9 javascript events dom-events animate.css reactjs
我正在使用带有React的animate.css库,并试图在悬停时设置一个元素(按钮).试图通过文档和这里查看,但无法找到实现这个简单任务的方法.如果有人已经实现了这个或发现参考将非常感激
class App extends Component {
constructor(props) {
super(props);
this.handleHover = this.handleHover.bind(this);
}
handleHover(){
this.setState({
isHovered: !this.state.isHovered
});
}
render() {
const btnClass = this.state.isHovered ? "pulse animated" : "";
return (
<div>
<button className={btnClass} onMouseEnter={this.state.handleHover} onMouseLeave={this.state.handleHover}>Test</button>
</div>
);
}
}
export default App;
Run Code Online (Sandbox Code Playgroud)
Cha*_*nda 28
您可以使用组件上的onMouseEnter和onMouseLeave事件并相应地切换类.
constructor(){
super();
this.state = {
isHovered: false
};
this.handleHover = this.handleHover.bind(this);
}
handleHover(){
this.setState(prevState => ({
isHovered: !prevState.isHovered
}));
}
render(){
const btnClass = this.state.isHovered ? "pulse animated" : "";
return <button className={btnClass} onMouseEnter={this.handleHover} onMouseLeave={this.handleHover}></button>
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17541 次 |
| 最近记录: |