悬停图像时如何向下滚动? [英] How to scroll down when hover an image?

查看:87
本文介绍了悬停图像时如何向下滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将鼠标悬停在图像上时,它将向下滚动到图像的末尾.

I want to when hovering an image, it will scroll down to the end of the image.

我有两个问题:

  1. 当用户将鼠标悬停在图像的末尾时,如何滚动到图像的末尾?目前,我开始将鼠标悬停在图片上,但没有滚动到图片的末尾.

  1. How to scroll to end of the image when user hover on it? Currently, I start hover on the image, it wasn't scrolled to end of the image.

将鼠标悬停在图像上时如何控制滚动速度?

How to control the speed of scroll when hovering on an image?

我的代码:

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:hover img {
  animation: moveSlideshow 3s linear;
}

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

.pic:hover .pic:after {
  opacity: 0;
}

<div class="pic"><img src="http://scr.templatemonster.com/51600/51651-big.jpg" alt="" /></div>


<div class="pic"><img src="http://www.cssauthor.com/wp-content/uploads/2014/06/Good-to-Go-single-page-PSD-template1.jpg" alt="" /></div>

推荐答案

这很好.我添加了一个calc,以便从图像的宽度减去div的高度,并且仅滚动到div的底部.

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:hover img {
  animation: moveSlideshow 3s linear;
  animation-fill-mode: forwards;
}

JSFiddle::此处

这篇关于悬停图像时如何向下滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆