How can one animate position using CSS -webkit-ani

2019-09-04 14:32发布

I want to make an image go from poitn a to point b. I can animate the blur, and scale smoothly but the position is not working. It doesn't flow as it should. I have tried it with translatex and translate y and it doesn't seem to respond. Can someone please give me a hand. Here is my code.

body {overflow:hidden;
margin: 0;}
		#bird {position: relative;
			-webkit-animation: birdfly 5s linear infinite;
  			animation: birdfly 5s linear infinite;
		}

@-webkit-keyframes birdfly {
  0% { 
    -webkit-filter: blur(15px);
    -webkit-transform: scale(0.7, 0.7);
    left:110px; top:200px;
  }
  
  }
   100% { 
    -webkit-filter: blur(0px);
    -webkit-transform: scale(1.8, 1.8);
    left:400px; top:600px;
  }
}

@keyframes birdfly {
  0% { 
    -webkit-filter: blur(15px);
    -webkit-transform: scale(0.7, 0.7);
    left:110px; top:200px;
  }
  
  }
   100% { 
    -webkit-filter: blur(0px);
    -webkit-transform: scale(1.8, 1.8);
    left:400px; top:600px;
  }
}
<html>
<head>
	<title>Animated image</title>
	<meta charset="utf-8">
</head>
<body>
	<div id="bird">
 		<img src="http://i556.photobucket.com/albums/ss3/t_wangrung/Bird/ibon.gif">
 	</div>
</body>
</html>

2条回答
叛逆
2楼-- · 2019-09-04 15:13

I edited your source.

body {overflow:hidden;
margin: 0;}
		#bird {position: relative;
			-webkit-animation: birdfly 5s linear infinite;
  			animation: birdfly 5s linear infinite;
		}

@-webkit-keyframes birdfly {
  0% { 
    -webkit-filter: blur(15px);
    -webkit-transform: scale(0.7, 0.7);
    -webkit-transform: translate(110px, 200px);
    transform: translate(110px, 200px);
  }
  
  }
   100% { 
    -webkit-filter: blur(0px);
    -webkit-transform: scale(1.8, 1.8);
    -webkit-transform: translate(400px, 600px);
    transform: translate(400px, 600px);
  }
}

@keyframes birdfly {
  0% { 
    -webkit-filter: blur(15px);
    -webkit-transform: scale(0.7, 0.7);
    -webkit-transform: translate(110px, 200px);
    transform: translate(110px, 200px);
  }
  
  }
   100% { 
    -webkit-filter: blur(0px);
    -webkit-transform: scale(1.8, 1.8);
    -webkit-transform: translate(400px, 600px);
    transform: translate(400px, 600px);
  }
}
<html>
<head>
	<title>Animated image</title>
	<meta charset="utf-8">
</head>
<body>
	<div id="bird">
 		<img src="http://i556.photobucket.com/albums/ss3/t_wangrung/Bird/ibon.gif">
 	</div>
</body>
</html>

You need to use the -webkit-transform: translate(translateX, translateY) property.

查看更多
来,给爷笑一个
3楼-- · 2019-09-04 15:15

If you're up for using jQuery, you can do it like this:

$("img").animate({
    left: newXValue,
    top: newYValue
});

For more details see: http://api.jquery.com/animate/

查看更多
登录 后发表回答