鼠标悬停在图片上出现蒙层的方法

关于蒙层实现的不同方法,我们可以用CSS和jQuery两种方法

Jquery方法

首先看一下HTML代码:

<div class="list_images"> <div class="content"> <img src="img/孤独症儿童行为检查量表(ABC) @2x.png" width="100%" /> <h3>孤独症儿童行为检查量表(ABC)</h3> <p>已有777人参与</p> <div class="mask"> <p class="mask_title">孤独症儿童行为检查量表(ABC)</p> <p class="mask_btn">立即参与</p> </div> </div> </div>

css代码:

.list_images { position: relative; width: 1000px; margin: 0 auto; text-align: center; } .content { margin-left: 26px; margin-top:18px; margin-bottom: 1%; height: 200px; width: 30%; position: relative; cursor: pointer; display: inline-block; box-shadow: 0px 3px 3px 0px rgb(0,0,0,0.05); } h3 { position: relative; color: #484848; font-size: 16px; font-weight: bold; left: 0px; } p { position: relative; left: -10px; color: #aaaaaa; font-size: 12px; } .mask { height: 100%; width: 100%; position: absolute; top: 0px; display: none; background-color: rgba(0, 0, 0, 0.5); color: #EEEEEE; font-size: 20px; } .mask_title { font-size:16px; margin-top: 20%; text-align: center; } .mask_btn { display: inline-block; text-decoration: none; color: #eee; width: 100px; height: 28px; line-height: 28px; font-size: 14px; text-align: center; border-radius: 14px; background: #5691fe; list-style: none; cursor: pointer; margin-top: 20px; }

jquery代码:

<script type="text/javascript"> $(' .content').mouseenter(function(){ $(this).find('.mask').show(); }); $('.content').mouseleave(function(){ $(this).find('.mask').hide(); }); </script>

Css方法:

只需要在css样式中再添加.content:hover .mask {display: block;}
Css 代码:

.list_images { position: relative; width: 1000px; margin: 0 auto; text-align: center; } .content { margin-left: 26px; margin-top:18px; margin-bottom: 1%; height: 200px; width: 30%; position: relative; cursor: pointer; display: inline-block; box-shadow: 0px 3px 3px 0px rgb(0,0,0,0.05); } h3 { position: relative; color: #484848; font-size: 16px; font-weight: bold; left: 0px; } p { position: relative; left: -10px; color: #aaaaaa; font-size: 12px; } .mask { height: 100%; width: 100%; position: absolute; top: 0px; display: none; background-color: rgba(0, 0, 0, 0.5); color: #EEEEEE; font-size: 20px; } .mask_title { font-size:16px; margin-top: 20%; text-align: center; } .mask_btn { display: inline-block; text-decoration: none; color: #eee; width: 100px; height: 28px; line-height: 28px; font-size: 14px; text-align: center; border-radius: 14px; background: #5691fe; list-style: none; cursor: pointer; margin-top: 20px; } .content:hover .mask {display: block;}

效果图

1638097-20190428105930499-770507610.png
----------------------------------------------------------------------------------------------------
1638097-20190428110006037-566627623.png

转载于:https://www.cnblogs.com/hellogmy/p/10782569.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值