图片/图形

纯CSS3鼠标滑过图片炫酷标题显示特效

阿里云


这是一款使用纯 css3 制作的鼠标滑过图片炫酷标题显示特效插件。该鼠标 hover 图片标题插件有 4 种效果:旋转效果,渐隐效果,放大效果和滑动效果。很多网站的图片鼠标滑过显示标题效果都是使用 jQuery 来完成的,现在,我们可以使用 CSS3 animations 来完成同样惊艳的效果。如果你对 CSS3 animations 还不了解,请先阅读 CSS3 animations。

HTML 结构

我们使用 html5 来制作这款插件。通过 figure 和 figcaption 来包装图片。4 个 demo 中 html 结构都是相同的。

也想出现在这里?联系我们
创客主机
  1. <figure>
  2.     <img alt="nerd girl" src="img/img3.jpg">
  3.     <figcaption>
  4.         <h3>I love this title!</h3>
  5.  
  6.         <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
  7.         eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
  8.  
  9.         <p><a href="#">Read More</a></p>
  10.     </figcaption>
  11. </figure>

DEMO 样式

在 demo1 中,将 figure 元素的 position 设置为相对定位(relative)。在这个例子中,标题和图片可以通过绝对定位相互堆叠到一起。

  1. img {width: 100%;}
  2. figure {
  3.     margin: 0;
  4.     padding: 0;
  5.     height: 300px;
  6.     position: relative;
  7.     display: block;
  8.     cursor: pointer;
  9.     overflow: hidden;
  10.     border: 3px solid #fff;
  11. }
  12. figure:hover figcaption {
  13.     -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
  14.     filter: alpha(opacity=100);
  15.     opacity: 1;
  16.     -webkit-transform: rotate(0);
  17.     -moz-transform: rotate(0);
  18.     -o-transform: rotate(0);
  19.     -ms-transform: rotate(0);
  20.     transform: rotate(0);
  21.     top: 0;
  22. }
  23. figcaption {
  24.     -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
  25.     filter: alpha(opacity=0);
  26.     opacity: 0;
  27.     position: absolute;
  28.     height: 100%;
  29.     width: 100%;
  30.     top: -100%;
  31.     background: rgba(0,0,0,.5);
  32.     color: #fff;
  33.     -webkit-transition: all .5s ease;
  34.     -moz-transition: all .5s ease;
  35.     -o-transition: all .5s ease;
  36.     -ms-transition: all .5s ease;
  37.     transition: all .5s ease;
  38.     -webkit-transition-delay: .5s;
  39.     -moz-transition-delay: .5s;
  40.     -o-transition-delay: .5s;
  41.     -ms-transition-delay: .5s;
  42.     transition-delay: .5s;
  43.     -webkit-transform: rotate(360deg);
  44.     -moz-transform: rotate(360deg);
  45.     -o-transform: rotate(360deg);
  46.     -ms-transform: rotate(360deg);
  47.     transform: rotate(360deg);
  48. }
  49. figcaption h3 {
  50.     font-family: 'Open sans';
  51.     font-weight: 400;
  52.     color: #f3b204;
  53.     padding: 10px 20px;
  54.     margin-bottom: 0;
  55.     position: relative;
  56.     left: 100%;
  57.     margin-top: 37px;
  58.     font-size: 30px;
  59.     -webkit-transition: all .5s;
  60.     -moz-transition: all .5s;
  61.     -o-transition: all .5s;
  62.     -ms-transition: all .5s;
  63.     transition: all .5s;
  64.     -webkit-transition-delay: 1s;
  65.     -moz-transition-delay: 1s;
  66.     -o-transition-delay: 1s;
  67.     -ms-transition-delay: 1s;
  68.     transition-delay: 1s;
  69. }
  70. figcaption p {
  71.     font-family: 'Open sans';
  72.     padding: 10px 20px;
  73.     margin-bottom: 0;
  74.     margin-top: 20px;
  75.     position: relative;
  76.     left: 100%;
  77.     font-size: 13px;
  78.     -webkit-transition: all .5s;
  79.     -moz-transition: all .5s;
  80.     -o-transition: all .5s;
  81.     -ms-transition: all .5s;
  82.     transition: all .5s;
  83.     -webkit-transition-delay: 1.3s;
  84.     -moz-transition-delay: 1.3s;
  85.     -o-transition-delay: 1.3s;
  86.     -ms-transition-delay: 1.3s;
  87.     transition-delay: 1.3s;
  88. }
  89. figure:hover h3,figure:hover p { left: 0; }
  90. figcaption a {
  91.     color: #fff;
  92.     border: 2px solid #fff;
  93.     padding: 4px 10px;
  94.     text-decoration: none;
  95. }
  96. figcaption a:hover {
  97.     color: #4f5856;
  98.     background: #fff;
  99. }

注意:在 figcaption 上使用 transition 来旋转它,这将使标题有一个非常好的旋转和圆滑的过渡效果。在某些 h3 和 p 元素上使用了 transition-delay,这使得它们在动画中有一些延迟。

纯 CSS3 鼠标滑过图片炫酷标题显示特效

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

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

发表回复

热销模板

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

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