支持w3c标准的随机漂浮代码,支持框架广告

时间:2008-03-08 04:26:30   来源:  作者:  点击:次  出处:技术无忧
关键字:w3c 广告代码 java

昨天就去各个搜索引擎搜索,今天还搜索,棱是没找到支持w3c标准的,可调用框架广告的随机漂浮js广告代码,
加起来搜索测试不下三四个小时,无奈啊,自己又不是很懂JS,

漂浮代码失效的原因如下:
在使用以下声明时,会使一个最常用的漂浮下拉广告失效
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

直接导致document.body.scrollTop永远等于0, body Scroll永远也不会引发。搜索了一下,发现了解决方案。

即是使用:document.documentElement.scrollTop 替代 document.body.scrollTop

所以我把document.body用document.documentElement替换掉,结果就好用了,真是应了毛主席的年啊句话了

“自己动手,丰衣足食”

共享代码如下:
<!--
var mvtWidth=130 //框架宽度
var mvtHeight=120 //框架高度
var mvtLink="/ad/movie/piao-2.htm" //框架地址

brOK=navigator.javaEnabled()?true:false
ns4=(document.layers)?true:false
ie4=(document.all)?true:false

if(ns4){
document.write('<layer id="mvt" width=40 height=60;"><iframe src="'+mvtLink+'" width="'+mvtWidth+'" height="'+mvtHeight+'"

MARGINWIDTH="0" MARGINHEIGHT="0" HSPACE="0" VSPACE="0" FRAMEBORDER="0" SCROLLING="no"><\/iframe><\/layer>');
}
else{
document.write('<div id="mvt" style="position:absolute; width:40; height:60;"><iframe src="'+mvtLink+'" width="'+mvtWidth+'"

height="'+mvtHeight+'" MARGINWIDTH="0" MARGINHEIGHT="0" HSPACE="0" VSPACE="0" FRAMEBORDER="0"

SCROLLING="no"><\/iframe><\/div>');
}

var vmin=2;
var vmax=5;
var vr=2;
var timer1;

function Chip(chipname,width,height)
{this.named=chipname;
this.vx=vmin+vmax*Math.random();
this.vy=vmin+vmax*Math.random();
this.w=width;
this.h=height;
this.xx=0;
this.yy=0;
this.timer1=null;
}

function movechip(chipname)
{
if(brOK)
{eval("chip="+chipname);
if(ns4)
{pageX=window.pageXOffset;
pageW=window.innerWidth;
pageY=window.pageYOffset;
pageH=window.innerHeight;
}
else
{pageX=window.document.documentElement.scrollLeft;
pageW=window.document.documentElement.offsetWidth-8;
pageY=window.document.documentElement.scrollTop;
pageH=window.document.documentElement.offsetHeight;
}

chip.xx=chip.xx+chip.vx;
chip.yy=chip.yy+chip.vy;

chip.vx+=vr*(Math.random()-0.5);
chip.vy+=vr*(Math.random()-0.5);
if(chip.vx>(vmax+vmin)) chip.vx=(vmax+vmin)*2-chip.vx;
if(chip.vx<(-vmax-vmin)) chip.vx=(-vmax-vmin)*2-chip.vx;
if(chip.vy>(vmax+vmin)) chip.vy=(vmax+vmin)*2-chip.vy;
if(chip.vy<(-vmax-vmin)) chip.vy=(-vmax-vmin)*2-chip.vy;


if(chip.xx<=pageX)
{ chip.xx=pageX;
chip.vx=vmin+vmax*Math.random();
}
if(chip.xx>=pageX+pageW-chip.w)
{ chip.xx=pageX+pageW-chip.w;
chip.vx=-vmin-vmax*Math.random();
}
if(chip.yy<=pageY)
{ chip.yy=pageY;
chip.vy=vmin+vmax*Math.random();
}
if(chip.yy>=pageY+pageH-chip.h)
{ chip.yy=pageY+pageH-chip.h;
chip.vy=-vmin-vmax*Math.random();
}

if(ns4){
eval('document.'+chip.named+'.top ='+chip.yy);
eval('document.'+chip.named+'.left='+chip.xx);
}
else{
eval('document.all.'+chip.named+'.style.pixelLeft='+chip.xx);
eval('document.all.'+chip.named+'.style.pixelTop ='+chip.yy);
}
chip.timer1=setTimeout("movechip('"+chip.named+"')",100); //设置速度,数值越大速度越慢
}
}

function stopme(chipname)
{if(brOK)
{//alert(chipname)
eval("chip="+chipname);
if(chip.timer1!=null)
{clearTimeout(chip.timer1)}
}
}

var mvt;
function mvt()
{
mvt=new Chip("mvt",60,80);
if(brOK){
movechip("mvt");
}
}

window.onload=mvt

//-->

收藏:http://pc51.net/www/texiao/2008-03-07/js10247.html

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面

特别推荐