javascript 完美解决对联广告


//
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;
}
//
function maple_hide(num){
document.getElementById("maple"+num).style.display="none"; }
//
function floatjs(){
new couplet("maple1",100,1);
new couplet("maple2",450,8);
new couplet("maple3",100,-8);
//new couplet("maple4",450,-8);
}
if( window.addEventListener) window.addEventListener('load',floatjs,false);
else window.attachEvent('onload',floatjs);
//
document.write('<div id="maple1"><a href="http://www.k686.com/" target="_blank"><img src="http://www.lygnk.com/images/shinian.jpg" border="0" /></a><div style="position: absolute;width:30px;height:30px;top:0px;right:5px;cursor:pointer" onclick="maple_hide(1)">XX</div></div>');
document.write('<div id="maple2"><a href="http://www.k686.com/" target="_blank"><img src="http://www.lygnk.com/images/shinian.jpg" border="0" /></a><div style="position: absolute;width:30px;height:30px;top:0px;right:5px;cursor:pointer" onclick="maple_hide(2)">XX</div></div>');
document.write('<div id="maple3"><a href="http://www.k686.com/" target="_blank"><img src="http://www.lygnk.com/images/shinian.jpg" border="0" /></a><div style="position: absolute;width:30px;height:30px;top:0px;right:5px;cursor:pointer" onclick="maple_hide(3)">XX</div></div>');
//document.write('<div id="maple4"><a href="http://www.k686.com/" target="_blank"><img src="http://www.lygnk.com/images/shinian.jpg" border="0" /></a></div>');

最新文章

  1. Flex Layout Attribute
  2. UrlEncode 和 HtmlEncode
  3. serialVersionUID的作用
  4. 阿里云centos yum源更换,两个文件是从阿里云服务器拷贝出来的,可安装openvpn
  5. Backbone.js
  6. Spring事务解析1-使用介绍
  7. 5.Firedac错误信息
  8. JS原生方法实现瀑布流布局
  9. 评论 ”[实例] 设计基于JQM的WebApp“
  10. 深入浅出百度地图API开发系列(3):模块化设计
  11. lua协程实现简析
  12. 用Raphael在网页中画圆环进度条
  13. arcgis api for silverlight使用google map等多个在线地图
  14. MySQL索引背后的数据结构及最左原则
  15. JqueryUI-2
  16. nnet3配置中的“编译”
  17. mysql-day1
  18. C语言错题集
  19. Linux 创建 时间命名 文件
  20. [java] 虚拟机(JVM)底层结构详解[转]

热门文章

  1. 基于axis1.4的webservice实例
  2. Nuxt 开发环境不支持ip访问?
  3. C#基础课程之四集合(ArrayList、List&lt;泛型&gt;)
  4. mapreduce 只使用Mapper往多个hbase表中写数据
  5. MySQL 自带工具使用介绍
  6. HR必备基础能力之人性
  7. Burpsuite如何抓取使用了SSL或TLS传输的 IOS App流量
  8. Python2.7 fabric理论学习
  9. Asp.Net模拟post提交数据方法
  10. VirtualBox中安装CentOS-7问题说明