兼容各大浏览器带关闭按钮的漂浮多组图片广告代码

JS部分: 


代码如下:

<script type="text/javascript" language="javascript">
function addEvent(obj, evtType, func, cap) {
cap = cap || false;
if (obj.addEventListener) {
obj.addEventListener(evtType, func, cap);
return true;
} else if (obj.attachEvent) {
if (cap) {
obj.setCapture();
return true;
} else {
return obj.attachEvent("on" + evtType, func);
}
} else {
return false;
}
}
function getPageScroll() {
var xScroll, yScroll;
if (self.pageXOffset) {
xScroll = self.pageXOffset;
} else if (document.documentElement && document.documentElement.scrollLeft) {
xScroll = document.documentElement.scrollLeft;
} else if (document.body) {
xScroll = document.body.scrollLeft;
}
if (self.pageYOffset) {
yScroll = self.pageYOffset;
} else if (document.documentElement && document.documentElement.scrollTop) {
yScroll = document.documentElement.scrollTop;
} else if (document.body) {
yScroll = document.body.scrollTop;
}
arrayPageScroll = new Array(xScroll, yScroll);
return arrayPageScroll;
}
function GetPageSize() {
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight) {
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else {
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) {
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) {
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) {
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
if (yScroll < windowHeight) {
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
if (xScroll < windowWidth) {
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}
arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
return arrayPageSize;
}
var AdMoveConfig = new Object();
AdMoveConfig.IsInitialized = false;
AdMoveConfig.ScrollX = 0;
AdMoveConfig.ScrollY = 0;
AdMoveConfig.MoveWidth = 0;
AdMoveConfig.MoveHeight = 0;
AdMoveConfig.Resize = function () {
var winsize = GetPageSize();
AdMoveConfig.MoveWidth = winsize[2];
AdMoveConfig.MoveHeight = winsize[3];
AdMoveConfig.Scroll();
}
AdMoveConfig.Scroll = function () {
var winscroll = getPageScroll();
AdMoveConfig.ScrollX = winscroll[0];
AdMoveConfig.ScrollY = winscroll[1];
}
addEvent(window, "resize", AdMoveConfig.Resize);
addEvent(window, "scroll", AdMoveConfig.Scroll);
function AdMove(id) {
if (!AdMoveConfig.IsInitialized) {
AdMoveConfig.Resize();
AdMoveConfig.IsInitialized = true;
}
var obj = document.getElementById(id);
obj.style.position = "absolute";
var W = AdMoveConfig.MoveWidth - obj.offsetWidth;
var H = AdMoveConfig.MoveHeight - obj.offsetHeight;
var x = W * Math.random(), y = H * Math.random();
var rad = (Math.random() + 1) * Math.PI / 6;
var kx = Math.sin(rad), ky = Math.cos(rad);
var dirx = (Math.random() < 0.5 ? 1 : -1), diry = (Math.random() < 0.5 ? 1 : -1);
var step = 1;
var interval;
this.SetLocation = function (vx, vy) { x = vx; y = vy; }
this.SetDirection = function (vx, vy) { dirx = vx; diry = vy; }
obj.CustomMethod = function () {
obj.style.left = (x + AdMoveConfig.ScrollX) + "px";
obj.style.top = (y + AdMoveConfig.ScrollY) + "px";
rad = (Math.random() + 1) * Math.PI / 6;
W = AdMoveConfig.MoveWidth - obj.offsetWidth;
H = AdMoveConfig.MoveHeight - obj.offsetHeight;
x = x + step * kx * dirx;
if (x < 0) { dirx = 1; x = 0; kx = Math.sin(rad); ky = Math.cos(rad); }
if (x > W) { dirx = -1; x = W; kx = Math.sin(rad); ky = Math.cos(rad); }
y = y + step * ky * diry;
if (y < 0) { diry = 1; y = 0; kx = Math.sin(rad); ky = Math.cos(rad); }
if (y > H) { diry = -1; y = H; kx = Math.sin(rad); ky = Math.cos(rad); }
}
this.Run = function () {
var delay = 10;
interval = setInterval(obj.CustomMethod, delay);
obj.onmouseover = function () { clearInterval(interval); }
obj.onmouseout = function () { interval = setInterval(obj.CustomMethod, delay); }
}
}
</script>

<script type="text/javascript" language="javascript">

var ad2 = new AdMove("ad2");
    ad2.Run();
    //多组漂浮

</script>

html部分:

代码如下:

<DIV id=ad2 style="Z-INDEX: 5;position:relative"><a href='PoliceHTk.aspx' target='_blank'><IMG src="images/fudong/fudong.jpg" width="230" height="150" border="0" > </a><br> <a href="#" onclick="document.getElementById('ad2').style.display='none'">                   <img border=0 src=images/fudong/close1.gif /></a>
</DIV>

(0)

相关推荐

  • js右下角与漂浮广告代码(兼容多浏览器)

    ie6 7 8 ff3.5 3.6 chrome 4.1.2 safari 主要代码如下: 我们右下角广告代码 html,body{ padding:0; margin:0; } 我在随平滚 我静止不动 function scrollx(p){ var d = document,dd = d.documentElement,db = d.body,w = window,o = d.getElementById(p.id),ie6 = /msie 6/i.test(navigator.userAg

  • js 居中漂浮广告

    程序源码 复制代码 代码如下: var floatAd = {}; floatAd.getScrollTop = function(node) { var doc = node ? node.ownerDocument : document; return doc.documentElement.scrollTop || doc.body.scrollTop; }; floatAd.getScrollLeft = function(node) { var doc = node ? node.ow

  • js 对联广告、漂浮广告封装类(IE,FF,Opera,Safari,Chrome

    /* 对联广告调用 第一个参数为ID,第二个参数图片,第三个参数广告距离顶部的距离, 第四个参数表示左右(true代表左,false代表右),第五个参数对联广告的宽度 */ new float_ad("ad_l","<img src='/System/uploads/allimg/090504/2346400.gif' />",50,true,64); new float_ad("ad_r","<img src='/S

  • JS随机漂浮广告代码具体实例

    复制代码 代码如下: <!--随机漂浮广告开始--><div id="float" style="position:absolute; z-index:3;(我建议大家把这里设为100,这样浮动图就不会被遮住了) left: 512px; width: 83px; top: 9px; height: 53px;">      <img src="piaofu.gif" width="100" he

  • 不用js多浏览器兼容纯DIV/CSS对联漂浮广告代码

    纯DIV/CSS对联漂浮广告代码(无JS) 源码网两侧漂浮.经测试,兼容IE6,IE7,Firefox浏览器. CSS代码为: 复制代码 代码如下: .r1{width:80px;height:80px;background:red;float:right;          position:fixed !important; top/**/:200px;          position:absolute; z-index:300; top:expression(offsetParent.

  • js实现广告漂浮效果的小例子

    复制代码 代码如下: <html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title></title><style type="text/css">div{position:absolute;}</style></head><body

  • 兼容性非常好的js右下角与漂浮广告代码

    兼容ie6 7 8 ,ff3.5 3.6,chrome 4.1.2,safari 重新修正 1.滚动时抖动的问题,主要体现在ff3.6上 2.加入了ie6下的固定 3.分成了两个块,xhtml,html解析 4.随着屏幕大小而变动 兼容ie6 7 8 ff3.5 3.6 chrome 4.1.2 safari xhtml1.0解析 Untitled Document html,body{ padding:0; margin:0; } 我在随平滚 我静止不动 function scrollx(p)

  • js实现全屏漂浮广告移入光标停止移动

    复制代码 代码如下: <!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>JS全屏漂浮广告</title><style type="text/css">div#roll{width:100px;height:10

  • xScrollStick 跟随滚动条漂浮的JS特效

    这是一个跟随滚动条漂浮的JS特效,就是说滚动条滚动而元素相对屏幕位置不变 网上有很多类似的效果,本代码比较起来有如下优点: 1. 兼容IE6.0+ & FF1.5+ 2. 使用非常简单,属于菜鸟最爱的那种拿来就能用的,见下面说明 3. 元素之间不会起冲突,一页中可以有n个特效,多元素使用无代码冗余 缺点有: 1. 只能在声明为xHTML的文档中使用 2. 元素最好放在body下 3. 滚动时不可避免的会有闪烁(已经比较轻微,但追求完美者可能觉得不爽) 使用说明: 在页面中引用JS包,然后在需要特

  • js漂浮广告实现代码(合集经典) 符合W3C

    第一种 漂浮广告 不符合W3CJavaScript漂浮广告代码,很不错,代码精简,不过一次只有漂一个,复制就能用了.希望站长朋友喜欢. 漂浮广告 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.c

随机推荐