Animation How to - Hover to slide image








Question

We would like to know how to hover to slide image.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.screen {<!-- w w w  . ja  v  a  2s . co m-->
  overflow: hidden;
  width: 320px;
  height: 568px;
}

.slider {
  position: relative;
  float: left;
  height: 568px;
  width: 700px;
  left: 0;
  -webkit-transition: all 0.5s ease-in-out;
  transition: all 0.5s ease-in-out;
}

.slider img {
  position: relative;
  float: left;
  height: 568px;
  width: 320px;
}

.screen:hover .slider {
  left: -320px;
}
</style>
</head>
<body>
  <div class="screen">
    <div class="slider">
      <img src="http://placehold.it/200x200"> 
      <img src="http://placehold.it/201x201">
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: