本节内容:
js实现的悬浮广告代码
例子:
1,js脚本部分
复制代码 代码示例:
<script>
lastScrollY=0;
function heartBeat(neryid){
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
diffY = document.documentElement.scrollTop;
else if (document.body)
diffY = document.body.scrollTop
else
{/*Netscape stuff*/}
percent=.1*(diffY-lastScrollY);
if(percent>0)percent=Math.ceil(percent);
else percent=Math.floor(percent);
document.getElementById(neryid).style.top=parseInt(document.getElementById(neryid).style.top)+percent+"px";
lastScrollY=lastScrollY+percent;
}
function hidethis(neryid){
document.getElementById(neryid).style.visibility="hidden";
}
window.setInterval("heartBeat('goods')",1);
</script>
2,html部分
复制代码 代码示例:
<div id="goods" style="width:50px; height:300px; position:absolute; background-color:yellow; right: 10px; top: 200px;">
脚本学堂提示:此处旋转内容,然后测试悬浮广告的效果。
</div>