jQuery浮动广告是一种使用jQuery库实现的网页广告,它可以在页面上浮动显示,通常用于吸引用户的注意力,推广产品或服务。这种广告可以是静态图片、动画效果或者富媒体内容。
以下是一个简单的jQuery浮动广告示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery浮动广告</title>
<style>
#floating-ad {
position: fixed;
bottom: 10px;
right: 10px;
width: 200px;
height: 100px;
background-color: #f9f9f9;
border: 1px solid #ccc;
padding: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<div id="floating-ad">
<p>这是一个浮动广告</p>
<button id="close-ad">关闭</button>
</div>
<script>
$(document).ready(function() {
// 关闭广告按钮事件
$('#close-ad').click(function() {
$('#floating-ad').hide();
});
// 广告跟随滚动效果
$(window).scroll(function() {
var scrollTop = $(window).scrollTop();
var windowHeight = $(window).height();
var documentHeight = $(document).height();
if (scrollTop + windowHeight >= documentHeight - 100) {
$('#floating-ad').css('bottom', '10px');
} else {
$('#floating-ad').css('bottom', '100px');
}
});
});
</script>
</body>
</html>
通过以上方法,可以有效地实现和管理jQuery浮动广告,提升用户体验和广告效果。
领取专属 10元无门槛券
手把手带您无忧上云