【发布时间】:2020-06-29 21:10:50
【问题描述】:
我想用 onclick 为我的按钮设置动画,但它不起作用:
css 文件(style.css):
.slide-out-top {
-webkit-animation: slide-out-top 1s cubic-bezier(0.550, 0.085, 0.680, 0.530) both;
animation: slide-out-top 1s cubic-bezier(0.550, 0.085, 0.680, 0.530) both;
}
@-webkit-keyframes slide-out-top {
0% {
-webkit-transform: translateY(0);
transform: translateY(0);
opacity: 1;
}
100% {
-webkit-transform: translateY(-1000px);
transform: translateY(-1000px);
opacity: 0;
}
}
@keyframes slide-out-top {
0% {
-webkit-transform: translateY(0);
transform: translateY(0);
opacity: 1;
}
100% {
-webkit-transform: translateY(-1000px);
transform: translateY(-1000px);
opacity: 0;
}
}
.slide-out-bottom {
-webkit-animation: slide-out-bottom 1s cubic-bezier(0.550, 0.085, 0.680, 0.530) both;
animation: slide-out-bottom 1s cubic-bezier(0.550, 0.085, 0.680, 0.530) both;
-webkit-animation-timing-function: ease;
animation-timing-function: ease;
}
@-webkit-keyframes slide-out-bottom {
0% {
-webkit-transform: translateY(0);
transform: translateY(0);
opacity: 1;
}
100% {
-webkit-transform: translateY(1000px);
transform: translateY(1000px);
opacity: 0;
}
}
@keyframes slide-out-bottom {
0% {
-webkit-transform: translateY(0);
transform: translateY(0);
opacity: 1;
}
100% {
-webkit-transform: translateY(1000px);
transform: translateY(1000px);
opacity: 0;
}
}
jsx 文件(preact):
import { h, Component } from 'preact';
import "../../style/index.css";
import "../../style/bootstrap.min.css";
import "./style.css";
export default class Home extends Component {
buttonExit = () => {
document.getElementById('buttonToExit').className = 'btn btn-outline-light slide-out-bottom';
document.getElementById('textToExit').className = 'pt-5 pb-3 font-weight-bold text-light h1 slide-out-top';
}
render = () => {
return (
<div className="App vh-100">
<div className="h-70 container">
<div className="py-5"> </div>
<div className="py-5" style={{ width: "100%" }}>
<div class="container">
<div class="row">
<div class="col-sm"> </div>
<div class="col text-center">
<div id="textToExit" className="pt-5 pb-3 font-weight-bold text-light h1">Accès en ligne</div>
<button type="button" id="buttonToExit" onClick={this.buttonExit} className="btn btn-outline-light">Se Connecter</button>
</div>
<div class="col-sm"> </div>
</div>
</div>
</div>
</div>
</div>
);
}
}
style.css 与 js 文件位于同一文件夹中。
我的函数应该修改按钮和文本元素的“类名”。 经过几次测试,该函数似乎被很好地调用了,并且动画正常运行。
有人可以帮帮我吗?
【问题讨论】:
标签: javascript html css jsx preact