How can one animate position using CSS -webkit-animation

风格不统一 提交于 2019-12-13 06:13:50

问题


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>

回答1:


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.




回答2:


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/



来源:https://stackoverflow.com/questions/28644962/how-can-one-animate-position-using-css-webkit-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!