图片/图形

CSS3鼠标滑过图片快速切换展示效果

阿里云


这是一款纯 css3 制作的鼠标滑过图片快速切换展示效果。该图片快速切换展示效果类似于电影中的快镜头播放效果,在鼠标滑过或鼠标悬停在图片上的时候,容器中的图片快速播放,鼠标离开后图片暂停播放。整个快速播放功能使用 CSS animations 完成,图片的播放和暂停使用的是 animation-play-state 。

HTML 结构

  1. <div class="hs-wrapper">
  2.     <img src="images/1.jpg" alt="image01"/>
  3.     <img src="images/2.jpg" alt="image02"/>
  4.     <img src="images/3.jpg" alt="image03"/>
  5.     <img src="images/4.jpg" alt="image04"/>
  6.     <img src="images/5.jpg" alt="image05"/>
  7.     <img src="images/6.jpg" alt="image06"/>
  8.     <img src="images/7.jpg" alt="image07"/>
  9.     <img src="images/8.jpg" alt="image08"/>
  10.     <div class="hs-overlay">
  11.         <span>Summer <strong>2014</strong></span>
  12.     </div>
  13. </div>
也想出现在这里?联系我们
创客主机

CSS 样式

为图片添加显示和隐藏动画效果。

  1. .hs-wrapper img{
  2.     top: 0px;
  3.     left: 0px;
  4.     position: absolute;
  5.     animation: showMe 0.8s linear infinite 0s forwards;
  6.     animation-play-state: paused;   
  7. }

只有鼠标滑过或悬停时图片才开始播放。其它部分 CSS 代码请参考下载文件。

  1. .hs-wrapper:hover img{
  2.     animation-play-state: running;
  3. }

播放效果只是简单的显示图片并将它放到容器的顶部。

  1. @keyframes showMe {
  2.     0% { visibility: visible; z-index: 100; }
  3.     12.5% { visibility: visible; z-index: 100; }
  4.     25% { visibility: hidden; z-index: 0; }
  5.     100% { visibility: hidden; z-index: 0; }
  6. }

现在所有的图片都有相同的 animation,但我们想为每个图片动画创建一些延时。我们还需要设置每张图片的 z-index。由于整个动画的时间为 0.8s,所以我们设置每张图片的延时为 0.1s(除了第一张图片)。

  1. .hs-wrapper img:nth-child(1){
  2.     z-index: 9;
  3. }
  4. .hs-wrapper img:nth-child(2){
  5.     animation-delay: 0.1s;
  6.     z-index: 8;
  7. }
  8. .hs-wrapper img:nth-child(3){
  9.     animation-delay: 0.2s;
  10.     z-index: 7;
  11. }
  12. .hs-wrapper img:nth-child(4){
  13.     animation-delay: 0.3s;
  14.     z-index: 6;
  15. }
  16. <!-- ... and so on -->

遮罩层的 css 代码如下:

  1. .hs-overlay{
  2.     position: absolute;
  3.     width: 100%;
  4.     height: 100%;
  5.     opacity: 0;
  6.     z-index: 500;
  7.     background: rgba(0,0,0,0.6);
  8.     box-shadow: 0 0 0 0 rgba(255,255,255,0.3) inset;
  9.     pointer-events: none;
  10.     transition: all 0.3s linear;
  11. }

当鼠标滑过时,显示遮罩层:

  1. .hs-wrapper:hover .hs-overlay{
  2.     opacity: 1;
  3.     box-shadow: 0 0 0 5px rgba(255,255,255,0.3) inset;
  4. }

更详细的 css 代码请参考下载文件。

CSS3 鼠标滑过图片快速切换展示效果

已有 497 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(1)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!