我們的項目,要求點擊微信圖標,彈出二維碼,點擊其他地方,彈框隱藏,然后我就寫了下
<div class="wechart"></div> <div class="absolute ewm whitebg" id="ewm"> <div class="text_sao red font14">掃一掃,你會了解更多</div> <div><img src="Images/index/ewm.png" /></div> </div>
.relative { position: relative; } .absolute { position: absolute; } .ewm{top:60px;left:50px;width:200px;padding:20px;box-sizing:border-box;display:none;} .text_sao{text-align:center;}
//點擊微信圖標彈出二維碼 $('.wechart').on('click', function () { $('.ewm').toggle(); //切換元素的可見狀態 return false; }) //點擊其他地方,二維碼隱藏 $(document).on({"click": function(e){ var src = e.target; if(src.id && src.id ==="ewm"){ return false; }else{ $('.ewm').hide(); } } });
好啦,現在就可以實現啦。