深夜了,还在写tab切换的核心类,很想把timer集成进去,却不行。
/**
* @author edwardpro@hellodigi.com
* @copyright hellodigi.com 2007~2008
* @projectDescription provide with you a tabs changes function
*/
var tabCore=function(tabs,tabsItem){
this._tabs=$(tabs);
this._timeout=0;//默认是0
this._curitem=0;// current item means who is the current object.
this._timer;
this._tabsitemObj=$(tabs).getElementsBySelector(tabsItem);
this.dochange=function(){}
this.enabletimer=function(){
this._timer=setInterval(this.dochange,this._timeout);
};
this.disabletimer=function(){
clearInterval(this._timer);
}
this.getcurObj=function(){
this._curitem=(this._curitem+1)%this._tabsitemObj.size();
//alert(this._curitem);
return this._tabsitemObj[this._curitem];
}; //单体执行ok
}
tabCore.prototype.addListen=function(dofunc,eventname){
//添加tab事件到主函数
for(var i=0;i<this._tabsitemObj.size();i++){
Event.observe(this._tabsitemObj[i], eventname, function(event) {
var elt = Event.element(event);
if(elt.tagName == "A"){
dofunc(elt);
}
});
}
}
tabCore.prototype.setdochange=function(dofunc){
this.dochange=function(){
this._curitem=(this._curitem+1)%this._tabsitemObj.size();
dofunc(this._tabsitemObj[this._curitem]); //调用之后却告诉我没有这个属性
};
}
tabCore.prototype.setTimer=function(timeout,func){
if(timeout){
this._timeout=timeout;
}else{
this._timeout=0;
}
this.setdochange(func);
this._timer=setInterval(this.dochange,this._timeout);
}
tabCore.prototype.test=function(){
alert(this._tabsitemObj.size());
}
看来和js的类核心有关,他的timer应该是只能接收类似静态函数的东西,唯一解释就是那个类当时并没有初始化,所以得不到属性值。不知道是方法问题还是什么。实现了半天实现了一个人家也做了的功能貌似还没有别人好用郁闷啊!!!
/**
* @author edwardpro@hellodigi.com
* @copyright hellodigi.com 2007~2008
* @projectDescription provide with you a tabs changes function
*/
var tabCore=function(tabs,tabsItem){
this._tabs=$(tabs);
this._timeout=0;//默认是0
this._curitem=0;// current item means who is the current object.
this._timer;
this._tabsitemObj=$(tabs).getElementsBySelector(tabsItem);
this.dochange=function(){}
this.enabletimer=function(){
this._timer=setInterval(this.dochange,this._timeout);
};
this.disabletimer=function(){
clearInterval(this._timer);
}
this.getcurObj=function(){
this._curitem=(this._curitem+1)%this._tabsitemObj.size();
//alert(this._curitem);
return this._tabsitemObj[this._curitem];
}; //单体执行ok
}
tabCore.prototype.addListen=function(dofunc,eventname){
//添加tab事件到主函数
for(var i=0;i<this._tabsitemObj.size();i++){
Event.observe(this._tabsitemObj[i], eventname, function(event) {
var elt = Event.element(event);
if(elt.tagName == "A"){
dofunc(elt);
}
});
}
}
tabCore.prototype.setdochange=function(dofunc){
this.dochange=function(){
this._curitem=(this._curitem+1)%this._tabsitemObj.size();
dofunc(this._tabsitemObj[this._curitem]); //调用之后却告诉我没有这个属性
};
}
tabCore.prototype.setTimer=function(timeout,func){
if(timeout){
this._timeout=timeout;
}else{
this._timeout=0;
}
this.setdochange(func);
this._timer=setInterval(this.dochange,this._timeout);
}
tabCore.prototype.test=function(){
alert(this._tabsitemObj.size());
}
看来和js的类核心有关,他的timer应该是只能接收类似静态函数的东西,唯一解释就是那个类当时并没有初始化,所以得不到属性值。不知道是方法问题还是什么。实现了半天实现了一个人家也做了的功能貌似还没有别人好用郁闷啊!!!