[英]CSS animation relative to current screen position
I'm trying to implement some CSS Keyframe animations on my application, which get triggered on different events.我正在尝试在我的应用程序上实现一些 CSS 关键帧动画,这些动画会在不同的事件上触发。
The animation consists of a unicorn flying up from the bottom of the screen, stopping in the middle for a second, and then moving up out of the screen. animation 由一只独角兽组成,它从屏幕底部飞起来,在中间停了一秒钟,然后向上移出屏幕。
The problem comes when different users have different amounts on content on the page, making the page height bigger.当不同的用户在页面上的内容数量不同时,就会出现问题,从而使页面高度变大。
This is my code so far:到目前为止,这是我的代码:
<img src="../***" v-if="aCounter === 1" class="unicornUp" alt="Unicorn">
.unicornUp {
position:absolute;
width:50%;
height:50%;
right:20%;
opacity: 0;
z-index:99;
animation-name: unicornMoveUp;
animation-duration: 3s;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
animation-iteration-count: 1;
animation-delay: 0.5s;
}
@keyframes unicornMoveUp {
from { bottom: 0; opacity: 1;}
20% {bottom:20%;opacity: 1;transform: rotate(5deg);}
40% {bottom: 50%;opacity: 1;}
60% {bottom: 50%;opacity: 1; transform: rotate(-5deg);}
80% {bottom: 60%; opacity: 1;}
100% {bottom: 90%; opacity: 0;}
}
I've been thinking about a sticky parent div, but I'm not sure if this is even correct and where to start.我一直在考虑一个粘性父 div,但我不确定这是否正确以及从哪里开始。
Any help would be appreciated!任何帮助,将不胜感激!
Try position: fixed
instead, as as opposed to position: absolute
which is relative to the entire document, fixed
is relative to the viewport ie the screen尝试position: fixed
,而不是position: absolute
相对于整个文档, fixed
相对于视口,即屏幕
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.