html - 如何使动画代码在 css 中工作?[代码对我不起作用...]
问题描述
我似乎找不到我的错误,你能帮帮我吗?
我已经放了-webkit-
前缀,所有元素都是有效的
这是代码:
div {
width:200px;
height:200px;
background-color:red;
-webkit-animation-name: easter;
-webkit-animation-duration: 3s;
-webkit-animation-timing-function: ease-in;
-webkit-animation-delay:1s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: reverse;
}
@-webkit-keyframes easter {
from {top: 0px;}
to {top: 200px;}
}
<div>
hi
</div>
我预计它会移动,但我不知道代码中的错误是什么
解决方案
你需要添加 position :relative;
到你的CSS
div {
width:200px;
height:200px;
background-color:red;
position :relative;
-webkit-animation: easter 5s infinite;
-webkit-animation-duration: 3s;
-webkit-animation-timing-function: ease-in;
-webkit-animation-delay:1s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: reverse;
animation: easter 5s infinite;
}
@-webkit-keyframes easter {
from {top: 0px;}
to {top: 200px;}
}
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<div>
hi
</div>
</body>
推荐阅读
- java - Rational Rhapsody 调试 JVM
- bash - 尽管文件名匹配,但用于检查文件是否存在的 Bash 命令不起作用
- javascript - 为什么函数不返回自定义对象?
- jquery - jquery随机背景 - 不同的eveytime
- c# - 在 Visual Studio 2015 上安装 nuget Fody 和 Costura.Fody 包时出现问题
- rpa - RPA- UiPath,关于特殊按键
- python - 我在哪里可以找到枕头模块的位置?
- python - django 频道连接错误仅在尝试使用 User_login 时出现
- swift - 初始化没有数据的 DictionaryLiteral
- jenkins - 在openshift中使用jenkins时,如何确保在正确的目录中调用了maven?