function next(elem){
do{
elem=elem.nextsibling;
}while(elem&&elem.nodetype!=1);
return elem;
}
//---鏌ユ壘绗竴涓瓙鍏冪礌鐨勫嚱鏁?--//
function first(elem){
elem=elem.firstchild;
return elem && elem.nodetype!=1?next(elem):elem;
}
var marquee = {
init : function(id,tofollow,speed){
this.speed = speed || 5;
this.boxid = id;
this.tofollow=tofollow;
this.scrollbox = document.getelementbyid(id);
if(this.tofollow=="top"||this.tofollow=="bottom"){
this.appendbox=first(this.scrollbox).clonenode(true);
this.scrollbox.appendchild(this.appendbox);
}else{
var templateleft = "
"+this.scrollbox.innerhtml+" | "+this.scrollbox.innerhtml+" |
";
this.scrollbox.innerhtml=templateleft;
this.appendbox=first(first(first(first(this.scrollbox))));
}
this.objs = {
scrollbox : this.scrollbox,
appendbox : this.appendbox,
tofollow : this.tofollow,
speed : this.speed,
id : this.boxid
};
return this;
},
scrollup : function(){
var self = this.objs;
self.begin = function(){
if(self['tofollow']=="top"){
self.doscr = setinterval(function(){
if(self['appendbox'].offsetheight<=self['scrollbox'].scrolltop){
self['scrollbox'].scrolltop-=first(self['scrollbox']).offsetheight;
}else{
self['scrollbox'].scrolltop++;
}
},self.speed);
}else if(self['tofollow']=="bottom"){
self.doscr = setinterval(function(){
if(self['scrollbox'].scrolltop<=0){
self['scrollbox'].scrolltop=self['appendbox'].offsetheight;
}else{
self['scrollbox'].scrolltop--;
}
},self.speed);
}else if(self['tofollow']=="left"){
self.doscr = setinterval(function(){
if(self['appendbox'].offsetwidth<=self['scrollbox'].scrollleft){
self['scrollbox'].scrollleft-=self['appendbox'].offsetwidth;
}else{
self['scrollbox'].scrollleft++;
}
},self.speed);
}else if(self['tofollow']=="right"){
self.doscr = setinterval(function(){
if(self['scrollbox'].scrollleft<=0){
self['scrollbox'].scrollleft=self['appendbox'].offsetwidth;
}else{
self['scrollbox'].scrollleft--;
}
},self.speed);
}
}
self.begin();
self.scrollbox.onmouseover = function(){
clearinterval(self.doscr);
}
self.scrollbox.onmouseout = function(){
self.begin();
}
}
}
// marquee.init("demo","top").scrollup();
// marquee.init("demo2","bottom", 50).scrollup();
// marquee.init("demo3","left").scrollup();
// marquee.init("demo4","right", 50).scrollup();