﻿//文字不停向上滚动
function TextScroll(id, width, height) {
    this._width = width;
    this._height = height;
    this._id = id;
    this._top = 0;
    this.select = function(objid) {
        return document.getElementById(objid);
    }
    this.Play = function() {
        //播放
        var contentobj = this.select(this._id + "_content");
        this._top = this._top-1;
        if (this._top <= -this._height) this._top = 0;
        contentobj.style.top = "" + this._top + "px";

    }
    this.Scroll = function() {
        //设置外框属性
        document.getElementById(this._id).style.position = "relative";
        document.getElementById(this._id).style.width = "" + this._width + "px";
        document.getElementById(this._id).style.height = "" + this._height + "px";
        document.getElementById(this._id).style.border = "0px solid";
        document.getElementById(this._id).style.overflow  = "hidden";

        var rawHtml = this.select(this._id).innerHTML;
        this.select(this._id).innerHTML = "<div id='" + this._id + "_content' style='position:absolute;top:0px;left:0px;'>" + rawHtml + rawHtml + "</div>";
        var _self = this;
        setInterval(function() { _self.Play(); }, 200);
    }
    this.Scroll();

}

//TextScroll("mydiv", 200, 150);