【发布时间】:2017-03-12 04:56:22
【问题描述】:
我想使用类切换为button 制作运动动画,就像在this example 中一样。由于某些原因,我的代码被破坏了:它调用了点击处理程序,但不影响类。
代码如下(我使用 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;
}
错在哪里?
【问题讨论】:
标签: javascript html css reactjs css-transitions