`
化蝶自在飞
  • 浏览: 2306419 次
  • 性别: Icon_minigender_2
  • 来自: 武汉
社区版块
存档分类
最新评论

js 对联广告 js 漂浮广告 js广告漂浮代码 js左右随屏移动对联广告

阅读更多
js 对联广告 js 漂浮广告 js广告漂浮代码 js左右随屏移动对联广告
js代码如下,请另存为 x.js 文件然后在目标页面引用.此代码兼容各浏览器,符号w3c标准.绝对可用.
function couplet(){ 
if(arguments.length>=1) this.objID = document.getElementById(arguments[0]); 
if(arguments.length>=2) this.divTop = arguments[1]; 
if(arguments.length>=3) this.divPlane = arguments[2]; 
if(arguments.length>=4) this.scrollDelay = arguments[4]; 
if(arguments.length>=5) this.waitTime = arguments[5]; 
if(!this.objID){ 
alert("对象名【"+ arguments[0] +"】无效,对联无法初始化,请检查对象名称是否正确!"); 
this.objID = null; return; 
}else{ 
this.objID.style.position="absolute"; 
this.objID.style.display="block"; 
this.objID.style.zIndex=9999; 
} 
if("" == this.objID.style.top){ 
if(isNaN(this.divTop)){ 
alert("对象垂直位置(top)参数必须为数字。"); return; 
}else{ 
this.objID.style.top = this.divTop+"px"; 
} 
} 
if("" == this.objID.style.left && "" == this.objID.style.right){ 
if(isNaN(this.divPlane)){ 
alert("对象水平位置(left||right)参数必须为数字。"); return; 
} 
if(this.divPlane>0) this.objID.style.left = this.divPlane+"px"; 
if(this.divPlane<0) this.objID.style.right = Math.abs(this.divPlane)+"px"; 
} 
if(this.scrollDelay<15 || isNaN(this.scrollDelay)) this.scrollDelay = 15; 
if(this.waitTime<500 || isNaN(this.waitTime)) this.waitTime = 500; 
if(arguments.length>=1) this.start(); 
} 
couplet.prototype.start = function(){ 
if(null == this.objID) return; 
var objCouplet = this; 
timer = this.scrollDelay; 
objCouplet.lastScrollY = 0; 
objCouplet.timerID = null; 
objCouplet.startID = function(){ 
if("block" == objCouplet.objID.style.display){ 
objCouplet.run(); 
}else{ 
clearInterval(objCouplet.timerID); 
} 
} 
objCouplet.Begin = function(){ 
objCouplet.timerID = setInterval(objCouplet.startID,timer); 
} 

setTimeout(objCouplet.Begin,this.waitTime); 
} 
couplet.prototype.run = function(){ 
if(document.documentElement && document.documentElement.scrollTop){ 
uu_scrY = parseFloat(document.documentElement.scrollTop); 
}else if(document.body){ 
uu_scrY = parseFloat(document.body.scrollTop); 
} 
uu_divX = parseFloat(this.objID.style.top.replace("px","")); 
uu_curTop = .1 * (uu_scrY - this.lastScrollY); 
uu_curTop = uu_curTop>0?Math.ceil(uu_curTop):Math.floor(uu_curTop); 
this.objID.style.top = parseFloat(uu_divX + uu_curTop) + "px"; 
this.lastScrollY += uu_curTop; 
}


在目标页面使用方法:
<script type="text/javascript" src="x.js"></script>
<script type="text/javascript">
function floatjs(){
new couplet("maple1",400,8); 
new couplet("maple2",400,-8); 
}
if( window.addEventListener) window.addEventListener('load',floatjs,false);
else window.attachEvent('onload',floatjs);
</script>
<div id="maple1"> 
<div>
<a href="http://www.k686.com/" target="_blank"><img src="http://shop.9qc.com/images/left.gif" title="k686绿色软件" border="0" /></a>
</div>
</div>
<div id="maple2"> 
<div>
<a href="http://www.k686.com/" target="_blank"><img src="http://shop.9qc.com/images/right.gif" title="k686绿色软件" border="0" /></a>
</div>
</div>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics