原生JS+CSS(CSS3)+HTML实现页面弹框
来源:互联网 发布:localstorage存储数据 编辑:程序博客网 时间:2024/06/06 02:05
—–看了很多网上弹框的实现,有的只是讲了一点,有的又太复杂了,所以自己动手下了一个,几分钟的事情;就是调试样式比较慢而已;之前用过一些js或者css框架中的弹框,感觉很复杂;也看过源代码;是想机制大同小异;
以下是截图:
以下是代码:
<!DOCTYPE html> <html> <head> <meta charset=""/> <title>opacity</title> <style> *{ padding: 0; margin: 0;}body{ padding: 0px; background: url() 0 0 no-repeat; background-size: cover;}.demo{ width: 100%; height: 100%; position: relative;}.demo-bg{ position: absolute; left: 0; top: 0; z-index: 0; width: 100%; height: 671px; /*filter:Alpha(opacity=50);*/ background-color: rgba(0,0,0,0.4); /*实现透明背景*/ display: none;}#button{ width: 70px; height: 30px; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; background: yellow; margin: 20px 0 0 40px; position: relative; border: 0; box-shadow: 2px 2px 10px red; -webkit-box-shadow: 2px 2px 10px red; -moz-box-shadow: 2px 2px 10px red;}.demo-txt{ position: relative; z-index: 1; color: #000; background: white; width: 30%; height: 200px; margin:auto; padding: auto; left: 0; right: 0; bottom: 0; top: 0; display: none; padding: 10px; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px;}#btn{ float: right;}</style></head><body> <div class='demo'> <button id="button" onclick="openDialog()">打开弹窗</button> <div class='demo-bg'></div> <div class='demo-txt'> <button id="btn" onclick="closeDialog()">关闭弹窗</button> </div></div><script> var demobg = document.querySelector(".demo-bg"); var demotxt = document.querySelector(".demo-txt"); function openDialog() { demotxt.style.display = "block"; demobg.style.display = "block"; } function closeDialog() { demotxt.style.display = "none"; demobg.style.display = "none"; }</script> </body></html>
2 0
- 原生JS+CSS(CSS3)+HTML实现页面弹框
- HTML+CSS3+JS 实现手风琴效果页面
- html页面js实现页面弹框
- html+css+js实现原生轮播特效
- JS原生轮播-基础篇(HTML+CSS)部分
- 完整html +css +原生js轮播图
- js实现单一html页面两套css切换
- Html+css+js+jquery实现简单页面登录
- html+css+js实现火影背景切换登录页面
- html&css实验8.(4)CSS3实现
- 前端页面使用js实现不同终端引入不同的html页面css样式js等
- 实现html页面及css3动画
- html+css+js实现弹出框+遮罩层
- HTML canvas原生js实现鼠标画图
- CSS3 特效按钮 + 原生JS递归实现fadeout
- 原生js+css3实现图片自动切换,图片轮播
- 原生JS、CSS3 上拉刷新效果的实现。
- css3+js+html实现模拟时钟
- IOS中使用sskeychain调用keychain(钥匙串)保存密码
- CCF-201412-4 最优灌溉(最小生成树)
- Mibatis 多对多
- C++ 多线程之临界区
- Socket鏈接與Http鏈接的區別
- 原生JS+CSS(CSS3)+HTML实现页面弹框
- LeetCode 34. Search for a Range
- boost的使用
- 数据仓库01
- 【J2SE】——流
- 前端冷知识集锦
- 小数、分数的计算
- 字符串与数组之间的转换
- TestNG-常用注解介绍