我希望使用类切换为button
创建移动动画,就像在this example中一样。由于某些原因,我的代码被破坏了:它调用了click处理程序,但不会影响类。
代码(我使用React,Classnames和Webpack):
index.jsx:
import React from "react";
import styles from "./index.css";
import classnames from "classnames";
export default class PlaylistButton extends React.Component {
onClick() {
alert("clicked");
$('.transform').toggleClass('transform-active');
}
render() {
return (
<button className = {classnames(styles.button, styles.transform)} onClick = {() => this.onClick()}>label</button>
);
}
}
index.css:
.button {
font-size: 30px;
color: white;
background-color: #5266ed;
margin-bottom: 5px;
border: none;
width: 300px;
height: 75px;
}
.transform {
-webkit-transition: all 2s ease;
-moz-transition: all 2s ease;
-o-transition: all 2s ease;
-ms-transition: all 2s ease;
transition: all 2s ease;
}
.transform-active {
margin-left: -200px;
}
错误是什么?