JavaScript 浮动广告类
/*
* File: KM.AD.js
* Description: KaiMo advertisement Class
* Author: Dnawo
* Date: 2009-07-22
*
* e.g.
*
* var ad = new KM.AD();
* ad.LeftTop = new KM.ADInfo("<a href='#' target='_blank'><img src='http://www.xuehuiba.com/it/200909/ad.gif' border='0' /></a>",137,182);
* ad.RightTop = new KM.ADInfo("<a href='#' target='_blank'><img src='http://www.xuehuiba.com/it/200909/ad.gif' border='0' /></a>",137,182);
* ad.LeftMiddle = new KM.ADInfo("<a href='#' target='_blank'><img src='http://www.xuehuiba.com/it/200909/ad.gif' border='0' /></a>",137,182);
* ad.RightMiddle = new KM.ADInfo("<a href='#' target='_blank'><img src='http://www.xuehuiba.com/it/200909/ad.gif' border='0' /></a>",137,182);
* ad.LeftBottom = new KM.ADInfo("<a href='#' target='_blank'><img src='http://www.xuehuiba.com/it/200909/ad.gif' border='0' /></a>",137,182);
* ad.RightBottom = new KM.ADInfo("<a href='#' target='_blank'><img src='http://www.xuehuiba.com/it/200909/ad.gif' border='0' /></a>",137,182);
* ad.Start();
*/
(function(){
//Namespace
if(!window.KM)window.KM={};
if(typeof window.KM != "object")throw new Error("'window.KM' is not an object!");
//Model Class
KM.ADInfo = function(html,width,height)
{
this.Html = html || "";
this.Width = typeof width == "number" ? width : 0;
this.Height = typeof height == "number" ? height : 0;
}
KM.ADInfo.prototype.toString = function(){
return "Html:" + this.Html + "rn" +
"Width:" + this.Width + "rn" +
"Height:" + this.Height + "rn";
};
//AD Class
KM.AD = function()
{
/*private members*/
//delay time, (milliseconds)
var _delay = 50;
//object initialize
var _initialize = function(html,width,height){
var div = document.createElement("div");
div.id = "km_" + (new Date()).getTime();
div.style.position = "absolute";
div.style.backgroundColor = "#FFFFFF";
div.style.overflow = "hidden";
div.style.top = "0px";
div.style.left = "0px";
div.style.width = width + "px";
div.style.height = height + "px";
div.innerHTML = html;
try{document.getElementsByTagName("body").item(0).appendChild(div)}catch(ex){};
return div;
}
//delete the unit