例子,一个js漂浮广告代码。
复制代码 代码示例:
<html>
<head>
<title>漂浮广告_www.jb200.com</title>
<body>
<div id="codefans_net" style="position:absolute">
<!--链接地址--><a href="#" target="_blank">
<!--图片地址--><img src="/images/logo.gif" border="0">
</a>
</div>
<script>
//js实现广告漂浮效果
var x = 50,y = 60
var xin = true, yin = true
var step = 1
var delay = 10
var obj=document.getelementbyid("codefans_net")
function float() {
var l=t=0
var r= document.body.clientwidth-obj.offsetwidth
var b = document.body.clientheight-obj.offsetheight
obj.style.left = x + document.body.scrollleft
obj.style.top = y + document.body.scrolltop
x = x + step*(xin?1:-1)
if (x < l) { xin = true; x = l}
if (x > r){ xin = false; x = r}
y = y + step*(yin?1:-1)
if (y < t) { yin = true; y = t }
if (y > b) { yin = false; y = b }
}
var itl= setinterval("float()", delay)
obj.onmouseover=function(){clearinterval(itl)}
obj.onmouseout=function(){itl=setinterval("float()", delay)}
</script>
</body>
</html>