Animation How to - Create slideshow of image using CSS3








Question

We would like to know how to create slideshow of image using CSS3.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
body:hover {<!--  w ww  .  j  av a2  s . c o  m-->
  -webkit-animation-play-state: paused;
  -moz-animation-play-state: paused;
}

#tech-slideshow {
  height: 221px;
  width: 332px;
  position: relative;
  overflow: hidden;
}

#tech {
  height: 221px;
  width: 660px;
  background: url(http://www.java2s.com/style/download.png);
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  -webkit-animation-play-state: paused;
  -webkit-animation: moveSlideshow 10s linear infinite;
  -moz-animation-play-state: paused;
  -moz-animation: moveSlideshow 10s linear infinite;
}

@-webkit-keyframes moveSlideshow { 0% {left: 0;}100%{left:-1328px;}}
@-moz-keyframes moveSlideshow { 0% {left: 0;}100%{left:-1328px;}}
#tech:hover {
  -webkit-animation-play-state: running;
  -moz-animation-play-state: running;
}
</style>
</head>
<body>
  <div id="tech-slideshow">
    <div id="tech"></div>
  </div>
</body>
</html>

The code above is rendered as follows: