原因:写一个很小的项目,没有必要引入大宗的插件例如:boostrap去实现特定的模态框功能
方案:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>简单的模态框(Modal)</title>
<style>
.modal {
display: block;
background: rgba(0, 0, 0, 0.6);
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 10;
100%;
height:100%;
font-size: 12px;
}
.btn-close {
color: #aaa;
font-size: 30px;
text-decoration: none;
position: absolute;
right: 5px;
top: 0;
}
.btn-close:hover {
color: #919191;
}
.modal-dialog {
background: #fefefe;
border: #333 solid 1px;
80%;
height:150px;
position: absolute;
top: 50%;
transform: translateY(-50%);
left: 0;
right: 0;
margin: 0 auto;
}
.modal-body {
padding: 10px 20px;
height: calc(100% - 105px);
overflow: auto;
}
.modal-header h2 {
font-size: 20px;
}
.modal-footer {
border-top: #eee solid 1px;
text-align: right;
position: absolute;
100%;
box-sizing: border-box;
bottom: 0;
}
.btn {
background: #428bca;
border: #357ebd solid 1px;
border-radius: 3px;
color: #fff;
display: inline-block;
font-size: 12px;
padding: 2px 5px;
text-decoration: none;
text-align: center;
min- 60px;
position: relative;
transition: color .1s ease;
}
.btn-new{
background: #fff;
border: #357ebd solid 1px;
border-radius: 3px;
color: #428bca;
display: inline-block;
font-size: 12px;
padding: 2px 5px;
text-decoration: none;
text-align: center;
min- 60px;
position: relative;
transition: color .1s ease;
}
.modal-header,
.modal-footer {
padding: 10px 20px;
}
.modal-header {
border-bottom: #eee solid 1px;
height:20px;
}
</style>
</head>
<body>
<div class="modal" id="commitModal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-header">
<span class="btn-close" id="close" aria-hidden="true">×</span>
</div>
<div class="modal-body">
中间的内容?
</div>
<div class="modal-footer">
<button class="btn-new" id ='cancel'>取 消</button>
<button class="btn" id="sure">确 定</button>
</div>
</div>
</div>
<script src="jquery-1.11.1.js"></script>
<script>
//点击内容不触发,阻止事件冒泡
$(".modal-dialog").click(function(e) {
e.stopPropagation();
});
//点击关闭
$("#close").click(function() {
$('#commitModal').css("display", 'none');
});
//点击取消
$("#cancel").click(function() {
$('#commitModal').css("display", 'none');
});
//点击确定
$("#sure").click(function(){
window.location.href='https://www.lanzous.com/ib5c8de'
})
</script>
</body>
</html>
ps:宽高需要根据需求自己更改