当前位置:起点学习辅导网培训频道电脑知识学习网页制作Javascript教程JavaScript 浮动广告类

JavaScript 浮动广告类

08-08 00:43:18浏览次数:909栏目:Javascript教程
标签:javascript视频教程,javascript教程下载, 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.qidian55.com/it/200909/ad.gif' border='0' /></a>",137,182);
*    ad.RightTop = new KM.ADInfo("<a href='#' target='_blank'><img src='http://www.qidian55.com/it/200909/ad.gif' border='0' /></a>",137,182);
*    ad.LeftMiddle = new KM.ADInfo("<a href='#' target='_blank'><img src='http://www.qidian55.com/it/200909/ad.gif' border='0' /></a>",137,182);
*    ad.RightMiddle = new KM.ADInfo("<a href='#' target='_blank'><img src='http://www.qidian55.com/it/200909/ad.gif' border='0' /></a>",137,182);
*    ad.LeftBottom = new KM.ADInfo("<a href='#' target='_blank'><img src='http://www.qidian55.com/it/200909/ad.gif' border='0' /></a>",137,182);
*    ad.RightBottom = new KM.ADInfo("<a href='#' target='_blank'><img src='http://www.qidian55.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
        var _deleteUnit = function(text){ return Math.round(("" + text).replace(/(px)$/g,""));};
        //
        var _me = this;
       
        /*public members*/
       
        this.Version = "1.0";
        this.Html = "";
        this.Width = 0;
        this.Height = 0;
       
        this.LeftTop = {}; //type of ADInfo
        this.RightTop = {}; //type of ADInfo
        this.LeftMiddle = {}; //type of ADInfo
        this.RightMiddle = {}; //type of ADInfo
        this.LeftBottom = {}; //type of ADInfo
        this.RightBottom = {}; //type of ADInfo

        this.Start = function(){
            if(this.LeftTop instanceof KM.ADInfo && !this.LeftTop.Element)
                this.LeftTop.Element = _initialize(this.LeftTop.Html,this.LeftTop.Width,this.LeftTop.Height);
            if(this.RightTop instanceof KM.ADInfo && !this.RightTop.Element)
                this.RightTop.Element = _initialize(this.RightTop.Html,this.RightTop.Width,this.RightTop.Height);
            if(this.LeftMiddle instanceof KM.ADInfo && !this.LeftMiddle.Element)

[1] [2] [3]  下一页

,JavaScript 浮动广告类
给资讯打分:
网友评论: