Articles

Moving a background image with css

Moving a background image with css

Use the following code to animate the background of any element
The example uses a div with the id of "myDIV"

 

<!DOCTYPE html>
<html>
<head>
<style> 
#myDIV {
  width: 300px;
  height: 200px;
  border: 1px solid black;
  background-image: url('smiley.gif');
  background-position: top left;
  animation: mymove 5s infinite;
}

@keyframes mymove {
  50% {background-position: center;}
}
</style>
</head>
<body>

<h1>Animation of background-position</h1>

<p>Gradually change the background-position from "top left" to "center", and back to "top left":<p>
<div id="myDIV"></div>

</body>
</html>

Total: 0 Comment(s)