鱼的生成方式是在div的background里面,代码是网上找的:
#fish{
width: 174px;
height: 126px;
position: absolute;
left:0;
top:0;
background:url(image/fish8.png) no-repeat left top;
animation:active1 0.8s steps(8) infinite;
}
@keyframes active1 {
0%{
}
100%{
background-position: left -1008px;
}
}
现在鱼相当于一个背景,但我想让鱼跟我设定的路径x,y坐标来走,应该怎么实现
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title> 页面名称 </title>
<style type="text/css">
#fish{
width: 300px;
height: 300px;
position: absolute;
left:0;
top:0;
background: url("https://avatar.csdn.net/5/6/7/3_jslang.jpg") no-repeat left top;
}
</style>
</head>
<body>
<div id="fish"></div>
<script type="text/javascript">
var x = 0, y = 0;
function move() {
x++;
y++;
document.getElementById("fish").style.backgroundPosition = x+"px "+y+"px";
if (x<280)
setTimeout(move,10);
}
move();
</script>
</body>
</html>
https://download.csdn.net/download/qq_34697613/9523003
#fish{
width: 174px;
height: 126px;
position: absolute;
left:0;
top:0;
overflow: hidden;
}
#fish:before{
content: "";
width: 100px;
height: 100px;
position: absolute;
left:0;
top:0;
background: url(image/fish8.png) no-repeat left top;
animation:active1 0.8s steps(8) infinite;
}
@keyframes active1 {
0%{ top: 0px; }
100%{ top: 100px; }
}
#fish:before{
content: "";
width: 100px;
height: 100px;
position: absolute;
left:0;
top:0;
background: url(image/fish8.png) no-repeat left top;
animation:active1 0.8s steps(8) infinite;
}
是这样吗?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title> 页面名称 </title>
<style type="text/css">
#fish{
width: 300px;
height: 300px;
position: absolute;
left:0;
top:0;
overflow: hidden;
}
#fish:before{
content: "";
width: 100px;
height: 100px;
position: absolute;
left:0;
top:0;
background: url("https://avatar.csdn.net/5/6/7/3_jslang.jpg") no-repeat left top;
animation:active1 0.8s steps(8) infinite;
}
@keyframes active1 {
0%{ left: 0px; top: 0px; }
100%{ left: 100px; top: 200px; }
}
</style>
</head>
<body>
<div id="fish"></div>
</body>
</html>
我有一个思路而已,毕竟我没学过这些
像地图在移动一样让角色在地图的中间