// jscript 文件 function marquee() { this.id = document.getelementbyid(arguments[0]); if(!this.id) { alert("您要设置的\"" + arguments[0] + "\"初始化错误\r\n请检查标签id设置是否正确!"); this.id = -1; return; } this.direction = this.width = this.height = this.delaytime = this.waittime = this.ctl = this.startid = this.stop = this.mouseover = 0; this.step = 1; this.timer = 30; this.directionarray = {"top":0 , "up":0 , "bottom":1 , "down":1 , "left":2 , "right":3}; if(typeof arguments[1] == "number" || typeof arguments[1] == "string")this.direction = arguments[1]; if(typeof arguments[2] == "number")this.step = arguments[2]; if(typeof arguments[3] == "number")this.width = arguments[3]; if(typeof arguments[4] == "number")this.height = arguments[4]; if(typeof arguments[5] == "number")this.timer = arguments[5]; if(typeof arguments[6] == "number")this.delaytime = arguments[6]; if(typeof arguments[7] == "number")this.waittime = arguments[7]; if(typeof arguments[8] == "number")this.scrollstep = arguments[8]; this.id.style.overflow = this.id.style.overflowx = this.id.style.overflowy = "hidden"; this.id.nowrap = true; this.isnotopera = (navigator.useragent.tolowercase().indexof("opera") == -1); if(arguments.length >= 7)this.start(); } marquee.prototype.start = function() { if(this.id == -1)return; if(this.waittime < 800)this.waittime = 800; if(this.timer < 50)this.timer = 50; if(this.width == 0)this.width = parseint(this.id.style.width); if(this.height == 0)this.height = parseint(this.id.style.height); if(typeof this.direction == "string")this.direction = this.directionarray[this.direction.tostring().tolowercase()]; this.halfwidth = math.round(this.width / 2); this.halfheight = math.round(this.height / 2); this.bakstep = this.step; this.id.style.width = this.width + "px"; this.id.style.height = this.height + "px"; if(typeof this.scrollstep != "number")this.scrollstep = this.direction > 1 ? this.width : this.height; var templateleft = "
msclass_temp_htmlmsclass_temp_html
"; var templatetop = "
msclass_temp_html
msclass_temp_html
"; var msobj = this; msobj.temphtml = msobj.id.innerhtml; if(msobj.direction <= 1) { msobj.id.innerhtml = templatetop.replace(/msclass_temp_html/g,msobj.id.innerhtml); } else { if(msobj.scrollstep == 0 && msobj.delaytime == 0) { msobj.id.innerhtml += msobj.id.innerhtml; } else { msobj.id.innerhtml = templateleft.replace(/msclass_temp_html/g,msobj.id.innerhtml); } } var timer = this.timer; var delaytime = this.delaytime; var waittime = this.waittime; msobj.startid = function(){msobj.scroll()} msobj.continue = function() { if(msobj.mouseover == 1) { settimeout(msobj.continue,delaytime); } else { clearinterval(msobj.timerid); msobj.ctl = msobj.stop = 0; msobj.timerid = setinterval(msobj.startid,timer); } } msobj.pause = function() { msobj.stop = 1; clearinterval(msobj.timerid); settimeout(msobj.continue,delaytime); } msobj.begin = function() { msobj.clientscroll = msobj.direction > 1 ? msobj.id.scrollwidth / 2 : msobj.id.scrollheight / 2; if((msobj.direction <= 1 && msobj.clientscroll <= msobj.height + msobj.step) || (msobj.direction > 1 && msobj.clientscroll <= msobj.width + msobj.step)) { msobj.id.innerhtml = msobj.temphtml; delete(msobj.temphtml); return; } delete(msobj.temphtml); msobj.timerid = setinterval(msobj.startid,timer); if(msobj.scrollstep < 0)return; msobj.id.onmousemove = function(event) { if(msobj.scrollstep == 0 && msobj.direction > 1) { var event = event || window.event; if(window.event) { if(msobj.isnotopera) { msobj.eventleft = event.srcelement.id == msobj.id.id ? event.offsetx - msobj.id.scrollleft : event.srcelement.offsetleft - msobj.id.scrollleft + event.offsetx; } else { msobj.scrollstep = null; return; } } else { msobj.eventleft = event.layerx - msobj.id.scrollleft; } msobj.direction = msobj.eventleft > msobj.halfwidth ? 3 : 2; msobj.abscenter = math.abs(msobj.halfwidth - msobj.eventleft); msobj.step = math.round(msobj.abscenter * (msobj.bakstep*2) / msobj.halfwidth); } } msobj.id.onmouseover = function() { if(msobj.scrollstep == 0)return; msobj.mouseover = 1; clearinterval(msobj.timerid); } msobj.id.onmouseout = function() { if(msobj.scrollstep == 0) { if(msobj.step == 0)msobj.step = 1; return; } msobj.mouseover = 0; if(msobj.stop == 0) { clearinterval(msobj.timerid); msobj.timerid = setinterval(msobj.startid,timer); } } } settimeout(msobj.begin,waittime); } marquee.prototype.scroll = function() { switch(this.direction) { case 0: this.ctl += this.step; if(this.ctl >= this.scrollstep && this.delaytime > 0) { this.id.scrolltop += this.scrollstep + this.step - this.ctl; this.pause(); return; } else { if(this.id.scrolltop >= this.clientscroll) { this.id.scrolltop -= this.clientscroll; } this.id.scrolltop += this.step; } break; case 1: this.ctl += this.step; if(this.ctl >= this.scrollstep && this.delaytime > 0) { this.id.scrolltop -= this.scrollstep + this.step - this.ctl; this.pause(); return; } else { if(this.id.scrolltop <= 0) { this.id.scrolltop += this.clientscroll; } this.id.scrolltop -= this.step; } break; case 2: this.ctl += this.step; if(this.ctl >= this.scrollstep && this.delaytime > 0) { this.id.scrollleft += this.scrollstep + this.step - this.ctl; this.pause(); return; } else { if(this.id.scrollleft >= this.clientscroll) { this.id.scrollleft -= this.clientscroll; } this.id.scrollleft += this.step; } break; case 3: this.ctl += this.step; if(this.ctl >= this.scrollstep && this.delaytime > 0) { this.id.scrollleft -= this.scrollstep + this.step - this.ctl; this.pause(); return; } else { if(this.id.scrollleft <= 0) { this.id.scrollleft += this.clientscroll; } this.id.scrollleft -= this.step; } break; } }