打开网页时会弹出这种悬浮广告代码,是css+js的代码吗?急求代码!
发布网友
发布时间:2022-04-21 00:20
我来回答
共1个回答
热心网友
时间:2022-04-21 01:50
就是一个div加上两个图片,你把div设为最外层,且宽度和高度为100%;
简单写了一个例子,可以参考一下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
overflow: hidden;
}
div {
height: 1000px;
width: 100%;
background-color: bisque;
float: left;
}
.app {
position: absolute;
height: 1000px;
top: 0;
left: 0;
width: 100%;
background-color: #666;
opacity: 0.5;
}
.app img {
width: 300px;
height: 300px;
/* 居中显示 */
position: absolute;
top: calc(50% - 150px);
left: calc(50% - 150px);
}
.app button {
position: absolute;
top: 0;
right: 10px;
width: 20px;
}
</style>
</head>
<body>
<div>
hello wrold
</div>
<div class="app">
<img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1537442890243&di=038db4517c43fd98c3d5d2c086593906&imgtype=0&src=http%3A%2F%2Fpic12.photophoto.cn%2F20090721%2F0035035938997045_b.jpg"
alt="小猫">
<!-- 没有关闭图标,用按钮演示 -->
<button>×</button>
</div>
<script>
var b = document.querySelector('button');
b.onclick = function () {
var div = document.querySelector('.app');
div.style.display = 'none';
}
</script>
</body>
</html>