jquery实现弹窗功能(窗口居中显示)
网络编程 2021-07-04 19:20www.168986.cn编程入门
本文主要介绍了jquery实现弹窗功能且弹出确认框始终位于窗口中间位置的实例,具有很好的参考价值,狼蚁网站SEO优化跟着长沙网络推广一起来看下吧
效果图
代码如下
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>弹出确认框始终位于窗口的中间位置的测试</title> <style type="text/css"> .mask { position: fixed; : 0; left: 0; width: 100%; height: 100%; background: #000; opacity: 0.5; filter: alpha(opacity=50); display: none; z-index: 99; } .mess { position: absolute; display: none; width: 250px; height: 100px; border: 1px solid #c; background: #ececec; text-align: center; z-index: 101; } </style> <script type="text/javascript" src="jquery-1.7.1.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('.btn').click(function() { $('.mask').css({'display': 'block'}); center($('.mess')); check($(this).parent(), $('.btn1'), $('.btn2')); }); // 居中 function center(obj) { var screenWidth = $(window).width(); screenHeight = $(window).height(); //当前浏览器窗口的 宽高 var scroll = $(document).scrollTop();//获取当前窗口距离页面顶部高度 var objLeft = (screenWidth - obj.width())/2 ; var objTop = (screenHeight - obj.height())/2 + scroll; obj.css({left: objLeft + 'px', : objTop + 'px','display': 'block'}); //浏览器窗口大小改变时 $(window).resize(function() { screenWidth = $(window).width(); screenHeight = $(window).height(); scroll = $(document).scrollTop(); objLeft = (screenWidth - obj.width())/2 ; objTop = (screenHeight - obj.height())/2 + scroll; obj.css({left: objLeft + 'px', : objTop + 'px','display': 'block'}); }); //浏览器有滚动条时的操作、 $(window).scroll(function() { screenWidth = $(window).width(); screenHeight = $(widow).height(); scroll = $(document).scrollTop(); objLeft = (screenWidth - obj.width())/2 ; objTop = (screenHeight - obj.height())/2 + scroll; obj.css({left: objLeft + 'px', : objTop + 'px','display': 'block'}); }); } //确定取消的操作 function check(obj, obj1, obj2) { obj1.click(function() { obj.remove(); closed($('.mask'), $('.mess')); }); obj2.click(function() { closed($('.mask'), $('.mess')); }) ; } // 隐藏 的操作 function closed(obj1, obj2) { obj1.hide(); obj2.hide(); } }); </script> </head> <body> <input type="button" class="btn" value="btn"/> <div>弹出确认框始终位于窗口的中间位置的测试</div> <div class="mask"></div> <div class="mess"> <p>确定要删除吗?</p> <p><input type="button" value="确定" class="btn1"/> <input type="button" value="取消"class="btn2"/></p> </div> </body> </html>
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望多多支持狼蚁SEO!
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指