点击按钮,弹出对话框
2016-07-03 19:52
330 查看
html代码:
CSS代码:
JS代码:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JS Bin</title> </head> <body> <button id="show">点我1</button> <div class="wrapper"> <div class="inner"> <div class="box"> <div class="top"> <span>我是标题1</span> <button class="close">x</button> </div> <p>我是内容1</p> <p>我是内容1</p> <div class="bottom"> <button class="agree">确定</button> <button class="cancle">取消</button> </div> </div> </div> </div> </body> </html>
CSS代码:
*{ margin:0; padding:0; } .wrapper{ width:100%; background:rgba(0,0,0,0.3); height:400px; position: absolute; top:0; display: none; } .active{display: block;} .inner{ width:280px; height:130px; position: absolute; top:50%; left:50% } .box{ background:#fff; border:1px solid #aaa; border-radius:8px; width:280px; height:130px; position: relative; top:-50%; left:-50%; } .box button{ border:none; background:none; float:right; font-size:18px; } .top{ padding:10px; border-bottom:1px solid #ccc; } p{ margin:10px; } .bottom{padding-right:10px}
JS代码:
var show = document.getElementById('show') var box = document.querySelector('.wrapper') show.addEventListener('click',function(){ box.setAttribute('class','wrapper active') }) var close = document.querySelector('.close') var cancle = document.querySelector('.cancle') close.addEventListener('click',function(){ box.setAttribute('class','wrapper') }) cancle.addEventListener('click',function(){ box.setAttribute('class','wrapper') })
相关文章推荐
- 弹幕实现
- bzoj1257(数学方法)
- 二分查找
- 权限相关和第三方库PermissionsDispatcher
- MySQL性能监控工具-MONyog
- 阿里云 windows2008自动更新windows日志文件使C盘变大
- 然并卵的1980年代的3D游戏眼镜往事,搞创新的你知道吗
- 给各阶段Java程序猿的学习建议
- 银行家算法
- MDI窗体
- Serial Port Programming on Linux(转载)
- laravel框架——保存用户登陆信息(session)
- javascript笔记
- Android------------>Activity 生命周期
- <Android 基础(十二)> TextInputLayout,让输入框更有灵性
- 最全面的常用正则表达式大全
- Python 语言及其应用 Chapter_4_Exercise
- uva 116 Unidirectional TSP
- Git版本控制工具在Android Studio中的使用
- react native 错误:Make sure you have an Android emulator running or a device connected and have set up