代码关闭了,我想添加图像,以便移动5张图像。出于某些原因,我尝试在此处放置我的代码,原因是它不允许我发布。我只写第一个,但是写的和我相似。4. div1 {background-image:url(“ newphoto1.jpg”); }。该图像与div1有关。它不起作用。原始代码如下:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 50px;
background-color: red;
font-weight: bold;
position: relative;
animation: mymove 5s infinite;
}
#div1 {animation-timing-function: linear;}
#div2 {animation-timing-function: ease;}
#div3 {animation-timing-function: ease-in;}
#div4 {animation-timing-function: ease-out;}
#div5 {animation-timing-function: ease-in-out;}
@keyframes mymove {
from {left: 0px;}
to {left: 300px;}
}
</style>
</head>
<body>
<p><strong>Note:</strong> The animation-timing-funtion property is not supported in Internet Explorer 9 and earlier versions.</p>
<div id="div1">linear</div>
<div id="div2">ease</div>
<div id="div3">ease-in</div>
<div id="div4">ease-out</div>
<div id="div5">ease-in-out</div>
</body>
</html>
background-size:
标签以避免裁剪:尝试将可能的代码片段添加到CSS文件中的每个元素中。设置background-size:
为background-size: 100% 100%;
此项可能会剪切图像,它将填满整个<div>
/ box。如果您不想使图像变形,请使用background-size: cover;
设置位置background-position:
。
background-image: url('./newphoto1.jpg');
background-size: 100% 100%;
下面,我在此可运行的Playground脚本中使用了一些随机测试图像:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 50px;
background-color: red;
font-weight: bold;
position: relative;
animation: mymove 5s infinite;
}
#div1 {animation-timing-function: linear;
background-image: url('https://picsum.photos/200');
background-size: 100% 100%;
}
#div2 {animation-timing-function: ease;
background-image: url('https://picsum.photos/200');
background-size: 100% 100%;
}
#div3 {animation-timing-function: ease-in;
background-image: url('https://picsum.photos/200');
background-size: 100% 100%;
}
#div4 {animation-timing-function: ease-out;
background-image: url('https://picsum.photos/200');
background-size: 100% 100%;
}
#div5 {animation-timing-function: ease-in-out;
background-image: url('https://picsum.photos/200');
background-size: 100% 100%;
}
@keyframes mymove {
from {left: 0px;}
to {left: 300px;}
}
</style>
</head>
<body>
<p><strong>Note:</strong> The animation-timing-funtion property is not supported in Internet Explorer 9 and earlier versions.</p>
<div id="div1">linear</div>
<div id="div2">ease</div>
<div id="div3">ease-in</div>
<div id="div4">ease-out</div>
<div id="div5">ease-in-out</div>
</body>
</html>
*请注意,将图像加载到此运动场脚本中并生效大约需要一秒钟。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句