做地图可视化项目时,经常要做蒙版效果,实现案例记录下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>test</title>
<style>
html,body {
overflow: hidden;
width: 100%;
height:100%;
}
.root-view {
position: relative;
width: 100%;
height: 100vh;
}
.background-placeholder {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
background-image: url(1.png);
background-repeat: no-repeat;
background-size: 100% 100%;
z-index: -1;
}
.mask {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
background-image: url(2.png);
background-repeat: no-repeat;
background-size: 100% 100%;
z-index: 10;
pointer-events: none;
}
.smartWaterModel, .oneMap {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
z-index: 1;
}
</style>
</head>
<body>
<div class="root-view">
<div class="background-placeholder"></div>
<div class="mask"></div>
<div class="oneMap">
<iframe style="width: 100%; height: 100%; margin: 0px; padding: 0px; border: none;" src="https://map.baidu.com" frameborder="0"></iframe>
</div>
</div>
</body>
</html>
样式中1.png
样式中2.png
效果如下: