图片/图形

鼠标滑过图片显示遮罩层特效

阿里云


这是一款使用 jQuery 和 CSS3 制作的炫酷的鼠标滑过图片显示遮罩层特效。该图片制作层特效共 6 种不同的效果,使用一些简单的 jQuery 代码和 CSS3 过渡效果来完成,简单实用,可以为网站图片添加非常不错的效果。

HTML 结构

该图片遮罩效果的基本 HTML 结构如下:

也想出现在这里?联系我们
创客主机
  1. <div id="effect-1" class="effects clearfix">
  2.     <div class="img">
  3.         <img src="img/jpg/1.jpg" alt="">
  4.         <div class="overlay">
  5.             <a href="#" class="expand">+</a>
  6.             <a class="close-overlay hidden">x</a>
  7.         </div>
  8.     </div>
  9.     ...
  10. </div>

在上面的.close-overlay 标签是一个关闭按钮,它用于在移动触摸设备中关闭遮罩层,在大屏幕显示器中你不会看到它。

CSS 样式

该图片遮罩层效果的通用 CSS 样式如下:

  1. .effects {
  2.   padding-left: 15px;
  3. }
  4. .effects .img {
  5.   position: relative;
  6.   float: left;
  7.   margin-bottom: 5px;
  8.   width: 25%;
  9.   overflow: hidden;
  10. }
  11. .effects .img:nth-child(n) {
  12.   margin-right: 5px;
  13. }
  14. .effects .img:first-child {
  15.   margin-left: -15px;
  16. }
  17. .effects .img:last-child {
  18.   margin-right: 0;
  19. }
  20. .effects .img img {
  21.   display: block;
  22.   margin: 0;
  23.   padding: 0;
  24.   max-width: 100%;
  25.   height: auto;
  26. }
  27.  
  28. .overlay {
  29.   display: block;
  30.   position: absolute;
  31.   z-index: 20;
  32.   background: rgba(0, 0, 0, 0.8);
  33.   overflow: hidden;
  34.   transition: all 0.5s;
  35. }
  36.  
  37. a.close-overlay {
  38.   display: block;
  39.   position: absolute;
  40.   top: 0;
  41.   right: 0;
  42.   z-index: 100;
  43.   width: 45px;
  44.   height: 45px;
  45.   font-size: 20px;
  46.   font-weight: 700;
  47.   color: #fff;
  48.   line-height: 45px;
  49.   text-align: center;
  50.   background-color: #000;
  51.   cursor: pointer;
  52. }
  53. a.close-overlay.hidden {
  54.   display: none;
  55. }
  56.  
  57. a.expand {
  58.   display: block;
  59.   position: absolute;
  60.   z-index: 100;
  61.   width: 60px;
  62.   height: 60px;
  63.   border: solid 5px #fff;
  64.   text-align: center;
  65.   color: #fff;
  66.   line-height: 50px;
  67.   font-weight: 700;
  68.   font-size: 30px;
  69.   border-radius: 30px;
  70. }

通过上面的通用 CSS 样式,已经为遮罩层,链接按钮和关闭按钮提供了必要的样式。下面是效果 1 的图片遮罩层样式:

  1. /* ============================================================
  2.   EFFECT 1 - SLIDE IN BOTTOM
  3. ============================================================ */
  4. #effect-1 .overlay {
  5.   bottom: 0;
  6.   left: 0;
  7.   right: 0;
  8.   width: 100%;
  9.   height: 0;
  10. }
  11. #effect-1 .overlay a.expand {
  12.   left: 0;
  13.   right: 0;
  14.   bottom: 50%;
  15.   margin: 0 auto -30px auto;
  16. }
  17. #effect-1 .img.hover .overlay {
  18.   height: 100%;
  19. }

JAVASCRIPT

该图片遮罩层特效使用 Modernizr 来检测浏览器,并在相应的事件中为图片添加和移除相应的 CLASS。

  1. $(document).ready(function(){
  2.     if (Modernizr.touch) {
  3.         // show the close overlay button
  4.         $(".close-overlay").removeClass("hidden");
  5.         // handle the adding of hover class when clicked
  6.         $(".img").click(function(e){
  7.             if (!$(this).hasClass("hover")) {
  8.                 $(this).addClass("hover");
  9.             }
  10.         });
  11.         // handle the closing of the overlay
  12.         $(".close-overlay").click(function(e){
  13.             e.preventDefault();
  14.             e.stopPropagation();
  15.             if ($(this).closest(".img").hasClass("hover")) {
  16.                 $(this).closest(".img").removeClass("hover");
  17.             }
  18.         });
  19.     } else {
  20.         // handle the mouseenter functionality
  21.         $(".img").mouseenter(function(){
  22.             $(this).addClass("hover");
  23.         })
  24.         // handle the mouseleave functionality
  25.         .mouseleave(function(){
  26.             $(this).removeClass("hover");
  27.         });
  28.     }
  29. });

鼠标滑过图片显示遮罩层特效

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

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

发表回复

热销模板

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

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