<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>通过偏移,遮罩层二维码图片绝对居中</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<style type="text/css">
.hide{
display: none !important;
}
.overHidden{
height: 100%;
overflow: hidden;
}
.qrcode-show{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: black;
opacity: 0.8;
}
.qrcode-show .qrcode-show-img{
display: block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 60%;
max-height: 100%;
margin-bottom: 10px;
}
</style>
</head>
<body class="container">
<h3>通过transform偏移,遮罩层二维码图片绝对居中</h3>
<button type="button" class="btn btn-default show-qrcode">显示遮罩层</button>
<!-- 遮罩层 -->
<section class="qrcode-show hide">
<img src="qrcode.jpg" alt="二维码" class="qrcode-show-img">
</section>
<!-- end遮罩层 -->
<script type="text/javascript">
$(function(){
// 显示二维码遮罩层
$(".show-qrcode").click(function(){
$(".qrcode-show").removeClass("hide");
// 禁止屏幕滚动
$("html,body").addClass("overHidden");
});
// 点击空白区域关闭遮罩层
/*$(".qrcode-show").click(function(e){
var _con = $('.qrcode-show-img'); // 设置目标区域[点击不会关闭遮罩层的区域]
if(!_con.is(e.target) && _con.has(e.target).length === 0){
$(".qrcode-show").addClass("hide");
// 解除禁止滚动
$("html,body").removeClass("overHidden");
}
});*/
// 点击空白区域关闭遮罩层,通过阻止冒泡事件实现
$(".qrcode-show").click(function(){
alert("点击空白区域");
$(".qrcode-show").addClass("hide");
// 解除禁止滚动
$("html,body").removeClass("overHidden");
});
$('.qrcode-show-img').click(function(){
alert("点击图片");
return false;
});
});
</script>
</body>
</html>

cfc0075
- 粉丝: 11
最新资源
- 【IOS应用源码】很精致的范围选择组件.zip
- 【IOS应用源码】很感恩---samplecode(end)归档 7.zip
- 【IOS应用源码】很炫的抽屉式侧边栏导航效果.zip
- 【IOS应用源码】很炫的底部导航.zip
- 【IOS应用源码】很炫的翻页效果.zip
- 【IOS应用源码】横向滚动的label.zip
- 【IOS应用源码】横条显示滚动的股票动态.zip
- 【IOS应用源码】黄色背景的警告提示弹出条.zip
- 【IOS应用源码】后台运行(Multitasking)以及本地通知(Local Notifications) 有图,有书,有代码,统一打包 BackgroundDemo(Beta4Fixed).zip
- 基于Matlab Simulink的风轮机发电系统多模块建模与仿真研究 v1.2
- 【IOS应用源码】华丽的创意和设计 26款经典iPhone开源应用.zip
- 【IOS应用源码】获取当前硬件可用内存的例子UIDevice.zip
- 【IOS应用源码】获取全球当前所有时区的当前时间TestTimeZone.zip
- 【IOS应用源码】加载器(当下载或加载缓存时候用的进度条).zip
- 【IOS应用源码】记事本界面.zip
- 【IOS应用源码】简单的google应用demo.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


