全功能广告代码:手机电脑自动识别,可关闭,带标识
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>全功能广告代码</title>
<style>
#ad-wrapper {
position: fixed;
display: none;
z-index: 9999;
background-color: #fff;
width: 300px;
height: 250px;
border: 1px solid #ccc;
padding: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
border-radius: 5px;
}
<pre><code> #ad-wrapper img {
max-width: 100%;
height: auto;
}
#ad-wrapper .close-btn {
position: absolute;
top: 5px;
right: 5px;
cursor: pointer;
}
#ad-wrapper .ad-label {
position: absolute;
bottom: 5px;
right: 5px;
font-size: 12px;
color: #999;
}
@media screen and (max-width: 768px) {
#ad-wrapper {
width: 100%;
height: 100%;
}
}
</style>
</code></pre>
</head>
<body>
<div id="ad-wrapper">
<img src="https://picsum.photos/300/250" alt="广告图片">
<div class="close-btn">x</div>
<div class="ad-label">广告</div>
</div>
<script>
var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
<pre><code> if (isMobile) {
// 手机端
document.getElementById('ad-wrapper').style.display = 'block';
} else {
// 电脑端
document.getElementById('ad-wrapper').style.display = 'block';
}
document.querySelector('.close-btn').addEventListener('click', function() {
document.getElementById('ad-wrapper').style.display = 'none';
});
</script>
</code></pre>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/lQS2 著作权归作者所有。请勿转载和采集!