Skip to content Skip to sidebar Skip to footer

How To Scroll Down When Hover An Image?

I want to when hovering an image, it will scroll down to the end of the image. I have two question: How to scroll to end of the image when user hover on it? Currently, I start hov

Solution 1:

This works fine. I added a calc so that from the width of the image, the height of the div is minused and it scrolls to the bottom of the div only.

CSS:

.pic:hoverimg {
  animation: moveSlideshow 3s linear;
  animation-fill-mode: forwards;
}

JSFiddle:here

Solution 2:

You can use the animation-fill-mode: forwards; property. For the speed, you can control it with the animation-duration property (i.e. I adjusted it to 0'6 seconds in the code snippet).

body {
  margin: 2px auto;
  width: 500px;
}

.pic {
  width: 48%;
  height: 200px;
  overflow: hidden;
  margin: 0 auto;
  display: inline-block;
  position: relative;
  cursor: pointer;
}

.pic:before {
  width: 100%;
  height: 200px;
  background: rgba(0, 0, 0, 0.5);
  position: absolute;
  top: 0;
}

.pic:after {
  color: #fff;
  font-size: 18px;
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -20px -25px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  padding: 10px;
}

img {
  max-width: 100%;
  cusor: pointer;
}

.pic:hoverimg {
  animation: moveSlideshow .6s linear forwards;
}

@keyframes moveSlideshow {
  100% {
    transform: translateY(-60%);
  }
}

.pic:hover.pic:after {
  opacity: 0;
}
<divclass="pic"><imgsrc="http://scr.templatemonster.com/51600/51651-big.jpg"alt="" /></div><divclass="pic"><imgsrc="http://www.cssauthor.com/wp-content/uploads/2014/06/Good-to-Go-single-page-PSD-template1.jpg"alt="" /></div>

Post a Comment for "How To Scroll Down When Hover An Image?"