时间:2021-07-01 10:21:17 帮助过:52人阅读
这里利用jquery实现两种弹窗效果:
1. 淡入弹窗效果:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>www.gxlcms.com jQuery弹窗</title> <style> *{padding: 0;margin: 0;} .box{width: 100%;height: 100%;} .main{width: 100%;height: 100%;background-color: rgba(0,0,0,0.8);display: none;position: fixed;z-index: 1;} .mainbox{width: 800px;height: 100%;margin: 0 auto;background-color: rgba(255,255,255,0.8);padding: 20px;} .kkk{width: 100%;height: 1200px;background-color: red;} .close{color: red;cursor: pointer;} </style> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> $(function(){ $(".btn").click(function(){ $(".main").fadeIn(); }); $(".close").click(function(){ $(".main").fadeOut(); }); }); </script> </head> <body> <p class="main"> <p class="mainbox"> <p class="close">点击关闭</p> </p> </p> <p class="box"> <p class="kkk"> <input class="btn" type="button" value="点击淡入弹窗" /> </p> </p> </body> </html>
运行效果:
2. 滑动弹窗效果:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>www.gxlcms.com jQuery弹窗</title> <style> *{padding: 0;margin: 0;} .box{width: 100%;height: 100%;} .main{width: 100%;height: 100%;background-color: rgba(0,0,0,0.8);display: none;position: fixed;z-index: 1;} .mainbox{width: 800px;height: 100%;margin: 0 auto;background-color: rgba(255,255,255,0.8);padding: 20px;display: none;} .kkk{width: 100%;height: 1200px;background-color: red;} .close{color: red;cursor: pointer;} </style> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> $(function(){ $(".btn").click(function(){ $(".main").fadeIn(); $(".mainbox").delay(500).slideDown(); }); $(".close").click(function(){ $(".main").fadeOut(); }); }); </script> </head> <body> <p class="main"> <p class="mainbox"> <p class="close">点击关闭</p> </p> </p> <p class="box"> <p class="kkk"> <input class="btn" type="button" value="点击淡入弹窗" /> </p> </p> </body> </html>
运行效果:
相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!
推荐阅读:
JS数组方法总结
js仿jquery步骤详解
以上就是jQuery实现弹窗效果(附代码)的详细内容,更多请关注Gxl网其它相关文章!