javascript - 部分重叠过渡动画
问题描述
我有这样的部分重叠。
function forPageOne() {
document.getElementById('home').style.zIndex = 200;
document.getElementById('about').style.zIndex = -200;
}
function forPageTwo() {
document.getElementById('home').style.zIndex = -200;
document.getElementById('about').style.zIndex = 200;
}
<section
style="
position: absolute;
width: 60vh;
height: 60vh;
background-color: #144ddc;
left: 300px;
"
class="page1 home"
id="home"
></section>
<section
style="
position: absolute;
width: 60vh;
height: 60vh;
background-color: #dcc114;
left: 300px;
"
class="page2 about"
id="about"
></section>
<button onclick="forPageOne()">For Page One</button>
<button onclick="forPageTwo()">For Page Two</button>
如果我单击一个按钮,该部分只是重叠,我不需要这只是发生。我需要添加动画部分,一个部分到另一个部分,我不知道如何做到这一点。如果你能帮助解决我的问题,我非常感谢。谢谢你..!
示例 - https://animista.net/play/basic/flip-scale/flip-scale-up-ver 当我的部分重叠时,我需要添加这样的动画
解决方案
您可以在单击时添加带有动画的类。
const page1 = document.getElementById('home');
const page2 = document.getElementById('about');
function forPageOne() {
page1.style.zIndex = 200;
page2.style.zIndex = -200;
page1.classList.add("animated");
page2.classList.remove("animated");
}
function forPageTwo() {
page1.style.zIndex = -200;
page2.style.zIndex = 200;
page1.classList.remove("animated");
page2.classList.add("animated");
}
@-webkit-keyframes flip-scale-up-ver {
0% {
-webkit-transform: scale(1) rotateY(0);
transform: scale(1) rotateY(0);
}
50% {
-webkit-transform: scale(2.5) rotateY(90deg);
transform: scale(2.5) rotateY(90deg);
}
100% {
-webkit-transform: scale(1) rotateY(180deg);
transform: scale(1) rotateY(180deg);
}
}
@keyframes flip-scale-up-ver {
0% {
-webkit-transform: scale(1) rotateY(0);
transform: scale(1) rotateY(0);
}
50% {
-webkit-transform: scale(2.5) rotateY(90deg);
transform: scale(2.5) rotateY(90deg);
}
100% {
-webkit-transform: scale(1) rotateY(180deg);
transform: scale(1) rotateY(180deg);
}
}
.animated {
-webkit-animation: flip-scale-up-ver 0.5s linear both;
animation: flip-scale-up-ver 0.5s linear both;
}
<section style="
position: absolute;
width: 60vh;
height: 60vh;
background-color: #144ddc;
left: 300px;
" class="page1 home" id="home"></section>
<section style="
position: absolute;
width: 60vh;
height: 60vh;
background-color: #dcc114;
left: 300px;
" class="page2 about" id="about"></section>
<button onclick="forPageOne()">For Page One</button>
<button onclick="forPageTwo()">For Page Two</button>
推荐阅读
- java - 又一个“比较法违背其总约”
- debugging - 调试器未在 Ubuntu 18.04.2 LTS 上的 QtCreator 4.0.3 中启动
- python - 如何从测试文件的列中获取元素
- android - Retrofit能否支持Android中同一个api的不同版本
- python-3.x - OPENPYXL For 循环遍历指定列中的每个单元格并将其值替换为大写字母
- python - 具有虚拟环境的 WSGI 应用程序中的 ImportError
- django - 如何与父级一起显示多个相关的外键
- angular - 没有使用 Angular Bootstrap 的 NgbDropdown 提供程序
- r - 时间序列数据分析
- javascript - AngularJS ng-messages在有效输入/缩小后没有隐藏 - 捆绑