jQuery 是一个快速、小巧且功能丰富的 JavaScript 库,它简化了 HTML 文档遍历、事件处理、动画和 Ajax 交互。首页广告弹窗是一种常见的网页设计元素,用于在用户访问网站首页时显示广告内容。
以下是一个简单的 jQuery 广告弹窗示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>广告弹窗示例</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
#popup {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}
#close-btn {
cursor: pointer;
}
</style>
</head>
<body>
<div id="popup">
<p>这是一个广告弹窗!</p>
<span id="close-btn">关闭</span>
</div>
<script>
$(document).ready(function() {
// 定时显示弹窗
setTimeout(function() {
$('#popup').fadeIn();
}, 3000);
// 关闭弹窗
$('#close-btn').click(function() {
$('#popup').fadeOut();
});
});
</script>
</body>
</html>
display: none
。通过以上信息,你应该能够更好地理解和实现 jQuery 首页广告弹窗功能。
领取专属 10元无门槛券
手把手带您无忧上云