【发布时间】:2020-02-24 05:32:33
【问题描述】:
我有一张大约占据屏幕底部三分之一的波浪图像(不是背景图像),我想在从右到左的无限循环上运行但使用 css。我尝试了不同的方法,但到目前为止都无法使其发挥作用。
我已经在 HTML 上定义了 img src,但如果需要我可以在 css 文件上进行。
感谢任何有关如何操作的帮助或建议。
CSS
body {
border: 2px solid black;
width: 700px;
background-image: url("./cave.jpg");
background-size: 700px 505px;
background-repeat: no-repeat;
background-position: 10px 10px;
}
.waves {
height: 380px;
width: 700px;
position: relative;
top: -300px;
background-repeat: repeat-x;
animation: animatedImage 20s linear infinite;
}
@keyframes animatedImage {
from {background-position: 0 0;}
to {background-position: 100% 0;}
}
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Escape the Cave</title>
<link rel="stylesheet" href="./jogo.css">
</head>
<body>
<div>
<img class="waves" src="./ondas.png">
</div>
<script src="jogo.js"></script>
</body>
</html>
【问题讨论】:
-
<img />元素的图像与background-image不同,您不能像使用 CSS 属性那样为<img />元素设置动画。
标签: html css image loops infinite-loop