手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >又一个不错的js浮动广告代码
又一个不错的js浮动广告代码
摘要:varRimifon={"Ads":newObject,"NewFloatAd":function(imgUrl,strLink){vara...

var Rimifon = { "Ads" : new Object, "NewFloatAd" : function(imgUrl, strLink) { var ad = document.createElement("a"); ad.DirV = true; ad.DirH = true; ad.AutoMove = true; ad.Image = new Image; ad.Seed = Math.random(); ad.Timer = setInterval("Rimifon.Float(" + ad.Seed + ")", 50); this.Ads[ad.Seed] = ad; ad.Image.Parent = ad; ad.style.position = "absolute"; ad.style.left = 0; ad.style.top = 0; ad.Image.src = imgUrl; ad.Image.onmouseover = function(){this.Parent.AutoMove = false;} ad.Image.onmouseout = function(){this.Parent.AutoMove = true;} if(strLink) { ad.href = strLink; ad.Image.border = 0; ad.target = "_blank"; } ad.appendChild(ad.Image); document.body.appendChild(ad); return ad; }, "Float" : function(floatId) { var ad = this.Ads[floatId]; if(ad.AutoMove) { var curLeft = parseInt(ad.style.left); var curTop = parseInt(ad.style.top); if(ad.offsetWidth + curLeft > document.body.clientWidth + document.body.scrollLeft - 1) { curLeft = document.body.scrollLeft + document.body.clientWidth - ad.offsetWidth; ad.DirH = false; } if(ad.offsetHeight + curTop > document.body.clientHeight + document.body.scrollTop - 1) { curTop = document.body.scrollTop + document.body.clientHeight - ad.offsetHeight; ad.DirV = false; } if(curLeft < document.body.scrollLeft) { curLeft = document.body.scrollLeft; ad.DirH = true; } if(curTop < document.body.scrollTop) { curTop = document.body.scrollTop; ad.DirV = true; } ad.style.left = curLeft + (ad.DirH ? 1 : -1) + "px"; ad.style.top = curTop + (ad.DirV ? 1 : -1) + "px"; } } }

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

更多代码下载:http://www.jb51.net/jiaoben/list500_1.html

【又一个不错的js浮动广告代码】相关文章:

一端时间轮换的广告

jquery任意位置浮动固定层插件用法实例

jquery实现的判断倒计时是否结束代码

一个特帅的展示图片的js+css

jquery判断至少有一个checkbox被选中的方法

一些很实用且必用的小脚本代码第1/5页

对联浮动广告效果

网页中移动的广告效果 鼠标悬停

将HTML自动转为JS代码

7个有用的jQuery代码片段分享

精品推荐
分类导航