【发布时间】:2022-08-21 17:53:58
【问题描述】:
我是一个前端初学者,我现在想制作一个效果! 当您点击红卡上的按钮时,让红色向下移动并淡出,而蓝卡则从上方滑下。 当你再次点击蓝色按钮时,它变成蓝色并向下移动淡出,红牌从上面滑下来。
但是我只是让红卡下移,当我想点击蓝卡的按钮时没有效果。 对不起,我的整个逻辑卡住了,我希望我能在这里寻求你的帮助,提前谢谢你。
我想做的效果类似于下面这个网址 enter link description here
let btn = document.querySelector(\'.btn\');
let btn2 = document.querySelector(\'.btn2\');
btn.addEventListener(\'click\', function() {
$(\'.card1\').addClass(\'active\');
})
btn2.addEventListener(\'click\', function() {
$(\'.card2\').addClass(\'active\');
})
body {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.wrap {
position: relative;
}
.wrap .card1 {
width: 500px;
height: 300px;
background-color: red;
border-radius: 20px;
display: flex;
justify-content: center;
align-items: flex-end;
}
.wrap .card1 .btn {
width: 100px;
height: 50px;
border-radius: 50px;
margin-bottom: 10px;
}
.wrap .card2 {
position: absolute;
top: 0px;
width: 500px;
height: 300px;
background-color: blue;
border-radius: 20px;
z-index: -1;
display: flex;
justify-content: center;
align-items: flex-end;
}
.wrap .card2 .btn2 {
width: 100px;
height: 50px;
border-radius: 50px;
margin-bottom: 10px;
}
.active {
-webkit-animation-iteration-count: 1;
animation-iteration-count: 1;
-webkit-animation-name: moveup;
animation-name: moveup;
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
@-webkit-keyframes moveup {
from {
opacity: 1;
}
to {
transform: translatey(20px);
display: none;
opacity: 0;
}
}
@keyframes moveup {
from {
opacity: 1;
}
to {
transform: translatey(20px);
display: none;
opacity: 0;
}
}
<script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>
<div class=\"wrap\">
<div class=\"card1\">
<input type=\"button\" value=\"save\" class=\"btn\">
</div>
<div class=\"card2\">
<input type=\"button\" value=\"recalculate\" class=\"btn2\">
</div>
</div>
标签: javascript jquery css animation