首页 > 代码库 > div 在页面上漂浮
div 在页面上漂浮
<div id="codefans_net" style="position:absolute;z-index:5;">
<a><img src="http://www.mamicode.com/template/[field:css_color]/images/float.jpg" border="0"></a><--漂浮图片-->
<br/>
<a target="_blank" style="cursor:pointer; position:absolute; right:10px; bottom:0px;" onclick="javascript:turnoff(‘codefans_net‘)"><font color="#FFFFFF">点击关闭<font/></a>
</div>
<script>
function turnoff(obj){
document.getElementById(obj).style.display="none";
}
</script>
<script>
var x = 50,y = 60
var xin = true, yin = true
var step = 1
var delay = 10
var obj=document.getElementById("codefans_net")
function floatpiao() {
var L=T=0
var R= document.documentElement.clientWidth-obj.offsetWidth
var B = document.documentElement.clientHeight-obj.offsetHeight
obj.style.left = x + document.documentElement.scrollLeft + ‘px‘;
obj.style.top = y + document.documentElement.scrollTop + ‘px‘;
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("floatpiao()", delay)
obj.onmouseover=function(){clearInterval(itl)}
obj.onmouseout=function(){itl=setInterval("floatpiao()", delay)}
</script>
div 在页面上漂浮