我正在为一个项目做一些页面过渡效果,当用户使用Barba浏览网站时,我有一个动画叠加层出现在屏幕上,但我遇到了问题。
我想在页面中心放置一个标志,随着叠加层一起滚动显示,但我需要将它与叠加层分开定位,因为对叠加层进行任何变换也会影响标志。(我希望标志与叠加层元素遮罩)
我尝试过:
- 切换元素层次结构/ Z-index(我确定问题在这里)
- 尝试不同的变换
- 更改最大宽度(取得了一些成功,但我需要变换原点属性)
示例 -
let transitionOpen = false;
$('.transition-cta').on("click", function() {
if (transitionOpen === false) {
$('.transition-background').css("transform", "scaleX(1)");
$(this).css("color", "white");
transitionOpen = true;
} else {
$('.transition-background').css("transform", "scaleX(0)");
$(this).css("color", "black");
transitionOpen = false;
}
});
body {
background-color: lightblue;
}
.someContent {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.transition-wrapper {
overflow: hidden;
}
.transition-background {
width: 100%;
height: 100vh;
position: absolute;
top: 0;
left: 0;
transform-origin: left;
transition: 0.7s ease-in-out;
background-color: #1f1f1f;
transform: scaleX(0);
z-index: 2;
}
.transition-center {
background-image: url('https://i.imgur.com/6um9G9h.png');
z-index: 2;
width: 150px;
height: 150px;
position: absolute;
background-repeat: no-repeat;
background-size: cover;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.transition-cta {
text-decoration: underline;
cursor: pointer;
z-index: 3;
position: absolute;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<div class="transition-wrapper">
<div class="transition-background"></div>
<!-- I want to clip this with the transition background -->
<div title="I only want this to show with the transition overlay" class="transition-center"></div>
</div>
<div class="transition-cta">Trigger Transition</div>
<div class="someContent">
<h1>Some Content</h1>
</div>
(地球应该与覆盖层一起滚动)
这感觉像一个非常简单的问题,但我真的很难解决。我无法确定是我已经筋疲力尽了,还是这实际上像我的大脑所想象的那样复杂。
谢谢!
.transition-wrapper
进行translateX(-100%)
,而非仅对.transition-background
使用scaleX(0)
。 - Thomas