jquery点击空白处或者自身隐藏弹出层
<script type="text/javascript"> $(function () { $(‘#btnShow‘).click(function (event) { //取消事件冒泡 event.stopPropagation(); //设置弹出层的位置 var offset = $(event.target).offset(); $(‘#divTop‘).css({ top: offset.top + $(event.target).height() + "px", left: offset.left }); //按钮的toggle,如果div是可见的,点击按钮切换为隐藏的;如果是隐藏的,切换为可见的。 $(‘#divTop‘).toggle(‘slow‘); }); //点击空白处或者自身隐藏弹出层,下面分别为滑动和淡出效果。 $(document).click(function (event) { $(‘#divTop‘).slideUp(‘slow‘) }); $(‘#divTop‘).click(function (event) { $(this).fadeOut(1000) }); }) </script>
<input type="button" id="btnShow" value="显示提示内容" /> <div id="divTop" style=" background-color:#99CCFF; border: solid 2px #ff0000; position:absolute; display:none; width:400px; height:200px;"> <div style="text-align:center;">点击本区域或空白隐藏弹出层</div> </div>
此地方用了toggle方法。
相关推荐
honeyth 2020-09-13
delmarks 2020-06-28
mjshldcsd 2020-08-15
Ping 2020-08-15
Kakoola 2020-08-01
Yellowpython 2020-08-01
chenguangchun 2020-07-26
dailinqing 2020-07-18
xiaouncle 2020-07-05
MayerF 2020-06-14
MrHaoNan 2020-06-13
smalllove 2020-06-09
JayFighting 2020-06-08
xiaoge00 2020-06-07
haokele 2020-05-31
matthewhan 2020-05-25
Alanxz 2020-05-20
jonychen 2020-04-22