本文是小編實現的一個簡單的jquery點擊彈出背景變暗遮罩效果,並且點擊空白處隱藏彈出層的效果,效果非常棒,小編只給大家貼出了關鍵代碼了,大家可以依個人需求適當的添加內容。
js程式碼如下:
<script type="text/javascript"> $(document).ready(function(){ $(".tkyy").click(function(event){ event.stopPropagation(); //停止事件冒泡 $(".marsk-container").toggle(); }); //点击空白处隐藏弹出层 $("body").click(function(event){ var _con = $('.tkyy_con'); // 设置目标区域 if(!_con.is(event.target) && _con.has(event.target).length ==0){ $('.marsk-container').hide(); //淡出消失 } }); }); </script>
css程式碼:
.marsk-container{background: #FFFFFF; display: none;position: absolute;position: fixed; top: 0; right: 0; left: 0; bottom: 0px; background: rgba(0,0,0,.5); z-index: 10; }
html程式碼:
<p class="tkyy"><span class="mui-icon mui-icon-arrowdown"></span>请选择退款类型 </p> <p class="marsk-container"> <p class="tkyy_con"> <p class="mui-input-row mui-radio "> <label>退运费</label> <input name="radio" type="radio" checked> </p> <p class="mui-input-row mui-radio "> <label>收到商品破损</label> <input name="radio" type="radio" checked> </p> <p class="mui-input-row mui-radio "> <label>少件/漏发</label> <input name="radio" type="radio" checked> </p> <p class="mui-input-row mui-radio "> <label>商品需要维修</label> <input name="radio" type="radio" checked> </p> <p class="mui-input-row mui-radio "> <label>发票问题</label> <input name="radio" type="radio" checked> </p> <p class="mui-input-row mui-radio "> <label>收到商品与描述不符</label> <input name="radio" type="radio" checked> </p> <p class="mui-input-row mui-radio "> <label>商品质量问题</label> <input name="radio" type="radio" checked> </p> <p class="mui-input-row mui-radio "> <label>描述问题</label> <input name="radio" type="radio" checked> </p> </p> </p>
效果如圖:
以上是利用jQuery實作點擊彈出背景變暗遮罩效果實例的詳細內容。更多資訊請關注PHP中文網其他相關文章!