ep8*_*p84 0 javascript css-animations reactjs codepen
我试图在点击它时让轮子图像旋转(CSS变换+过渡).现在,我只能在使用'img:active'按住鼠标按钮时旋转它.我已经找到了答案,并且通常会感觉我应该使用onClick来打开和关闭动画的类,但我似乎没有做得对.我究竟做错了什么?这是我的代码,供参考:
class Wheel extends React.Component
{
constructor(props){
super(props);
this.spin = this.spin.bind(this);
}
spin(e){
e.classList.toggle('rotate');
}
render(){
return (<div><img width="400" height="400" src="https://orig00.deviantart.net/0a38/f/2010/242/f/6/singapore_wheel_of_fortune_by_wheelgenius-d2xmb9v.jpg" onClick={this.spin}/>
</div>);
}
}
ReactDOM.render(
<Wheel/>,
document.getElementsByClassName('container-fluid')[0]
);
Run Code Online (Sandbox Code Playgroud)
CSS:
.rotate {
-webkit-transform: rotate(1095deg);
-webkit-transition: -webkit-transform 3s ease-out;
}
/*
img:active {
-webkit-transform: rotate(1095deg);
-webkit-transition: -webkit-transform 3s ease-out;
}
*/
Run Code Online (Sandbox Code Playgroud)
我已将所有内容放在CodePen上,网址为https://codepen.io/ejpg/pen/LmOVoR
先感谢您.
| 归档时间: |
|
| 查看次数: |
593 次 |
| 最近记录: |