87,993
社区成员
发帖
与我相关
我的任务
分享
$('.box').click(function(event){
$('body').append($modal);
event.stopPropagation();
});
$(document).click(function(event){
$modal.remove()
});
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.min.js"></script>
<title>Title</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
width: 100%;
height: 100%;
}
.box{
width: 100px;
height: 100px;
background: #7e7e7e;
}
.modal{
display:none;
width: 100%;
height: 100%;
position: fixed;
background: rgba(0,0,0,.3);
top:0;
left:0;
}
.on{
position: absolute;
top: 50%;
left: 50%;
width: 250px;
height: 150px;
margin-left: -150px;
margin-top: -100px;
background: #FFFFFF;
}
p{
font-size: 18px;
height: 50px;
line-height: 50px;
text-align:center;
}
button{
width: 100px;
height: 50px;
margin-left: 75px;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
<script>
var $modal = $(
'<div class="modal">'+
'<div class="on">'+
'<p class="pic">图片不清晰</p>'+
'<button>关闭</button>'+
'</div>'+
'</div>'
);
$('body').append($modal);
$("body").click(function(e){
if(e.target === $('.box').get(0)){return;}
$modal.hide();
});
$('.box').click(function(){
$modal.show();
});
</script>
</html>