如何在悬停图像时向下滚动?

时间:2017-08-20 05:34:17

标签: javascript html css hover

我想在悬停图像时,它会向下滚动到图像的末尾。

我有两个问题:

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

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

  3. 我的代码:

      File "/home/samuel/Documents/code/revamp/revamp/urls.py", line 92, in <module>
        url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
      File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py", line 85, in url
        raise TypeError('view must be a callable or a list/tuple in the case of include().')
    TypeError: view must be a callable or a list/tuple in the case of include().
    
    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;
    }

2 个答案:

答案 0 :(得分:1)

您可以使用animation-duration属性。对于速度,您可以使用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 .6s linear forwards; } @keyframes moveSlideshow { 100% { transform: translateY(-60%); } } .pic:hover .pic:after { opacity: 0; }属性控制它(即我在代码片段中将其调整为0'6秒)。

<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>
{{1}}

答案 1 :(得分:1)

这很好用。我添加了一个calc,以便从图像的宽度开始,div的高度是minused,它只滚动到div的底部。

<强> CSS:

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

JSFiddle: here