html - 使用 CSS 制作动画
问题描述
我正在尝试用 css & html 做一个“简单”的动画。我有一个图像,我想在进入页面的前 18 秒内隐藏它,之后,图像将可见并且动画将开始。动画应该以正方形的形式向屏幕两侧移动约 30 秒,然后它会消失。(就像从左下角到右下角,到右上角,右下角循环一样)。
我设法做到了一半,有点。图像隐藏的东西不工作,动画工作,但它在 30 秒后没有停止,而且,当我在另一台计算机尺寸上打开我的网站时,img 没有像我的笔记本电脑那样接触侧面(不同屏幕尺寸)。如果您能给我一个答案,我将不胜感激,谢谢!
我尝试了什么:
HTML:
.col-5 {
width: 100px;
height: 100px;
position: relative;
-webkit-animation: myfirst 3s 100;
/* Safari 4.0 - 8.0 */
-webkit-animation-direction: normal;
/* Safari 4.0 - 8.0 */
animation: myfirst 3s 100;
animation-direction: normal;
animation-delay: 18s;
}
/* Safari 4.0 - 8.0 */
@-webkit-keyframes myfirst {
0% {
bottom: 0px;
top: 440px;
left: 0px;
}
25% {
bottom: 0px;
top: 0px;
left: 0px;
}
50% {
bottom: 0px;
top: 0px;
left: 1020px;
}
75% {
bottom: 0px;
top: 440px;
left: 1020px;
}
100% {
bottom: 0px;
top: 440px;
left: 0px;
}
}
<div class='col-5'>
<img style="margin-left: 0%; margin-top: 31%;" src="..\static\kingjulien_iliketo1.gif" style="position:relative;" width="480" height="270" class="juliengif1"></img>
</div>
解决方案
animation:bottomleft 1s linear 1s forwards, .....
第二个 1s 是第一次启动延迟。你可以做到 18 多岁。我希望这是你想要的答案。
body {
margin:0;
}
.box {
height:50px;
width:50px;
background:#262626;
animation:bottomleft 1s linear 1s forwards, rightbottom 1s linear 2s forwards, righttop 1s linear 3s forwards, lefttop 1s linear 4s forwards;
position:absolute;
visibility:hidden
}
@keyframes bottomleft {
to {margin-top:calc(100vh - 50px);visibility:visible}
}
@keyframes rightbottom {
to {margin-left:calc(100vw - 50px)}
}
@keyframes righttop {
to {transform:translateY(calc(-100vh + 50px))}
}
@keyframes lefttop {
to{margin-top:0px;margin-bottom:calc(100vh - 50px);transform:translateX(calc(-100vw + 50px));}
}
<div class="box"></div>
推荐阅读
- node.js - 纱线警告“ > bootstrap@4.xx”具有未满足的对等依赖性“jquery@1.9.1 - 3”
- java - 在从另一个线程读取期间是否可以读取非易失性变量的陈旧值?
- angular - Angular 的虚拟 ngFor 去哪儿了?
- sql - SQL扩展表以合并具有重复数据的字段
- maven - Maven两个不同属性的jar文件
- java - 如何在 Spring mvc 中按屏幕权限应用屏幕?
- python - Python中的魔方旋转
- jquery - JQuery AJAX GET方法请求不起作用
- c - 结构数组上的 qsort 失败(分段错误 11)
- python - 从 jinja 变量动态传递变量