网站制作学习网JS脚本→正文:jquery浮动广告全浏览器兼容
字体:

jquery浮动广告全浏览器兼容

JS脚本 2013/1/19 16:33:58  点击:不统计


www-fo-a-sp.cn

在做一个广告代码时,用到了浮动窗口,在网上找了代码,但是不是所有浏览器兼容的,改了一下更改为jquery的代码,并能兼容各个浏览器

<html>
<head>
<title>漂浮广告</title>
<body>
<div id="forasp" style="position:absolute">
<!--链接地址--><a href="#" target="_blank">
<!--图片地址--><img src="/images/logo.gif" border="0">
</a>
</div>
<script>
var x = 0,y = 0;
var xin = true,yin = true;
var step = 1 ;
var itl,obj,L,T,R,B;
var delay =10 ;

function float() {
obj.offset({"left":x + document.body.scrollLeft,"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 }
}
$(window).load(function(){
   obj=$("#forasp");
    L=T=0;
    R = $(window).width()-obj.width();
    B = $(window).height()-obj.height();
})
$(function(){
  itl= setInterval("float()", delay)
   obj.mouseover(function(){
   clearInterval(itl);
  })
   obj.mouseout(function(){
   itl=setInterval("float()", delay); 
  });
 });

</script>

</body>
</html>


原文章%77w%77%2Ef%6F%72%61%73%70%2E%63n

·上一篇:kindeditor判断输入为空 >>    ·下一篇:javascript通过cookie读写key-value值 >>
推荐文章
最新文章