您的位置:首页 > 编程语言

网页右侧的漂浮广告代码,随滚动条滚动

2013-10-15 13:52 120 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>

<body>

HTML代码(即需要漂浮的广告):
<div class="christmas_ad" style="width:155px; height:220px; position:absolute; top:150px; right:25px;">
<a href="javascript:void(0)" ><img src="http://dlt.zoosnet.net/site/35433641/online_cn.gif" border="0" /></a>
</div>

js代码:前提是必须要引入jquery文件
<script type="text/javascript">
$(function(){
$(window).scroll(function(){
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop || 0;
$(".christmas_ad").stop();
var scrollTop2 = (scrollTop+160) - $(".christmas_ad").position().top;
if(scrollTop> 440){
$(".christmas_ad:not(:animated)").animate({top:"+="+scrollTop2+"px"},1000);
}else{
$(".christmas_ad").css("top",370+"px");
}
})
})
</script>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: