js 链表,浏览图片

来源:岁月联盟 编辑:exp 时间:2012-07-19

 $.links = {
  current:0,
  key:[],
  val:{},
  add:function (o){
    this.key.push(o.hash);
    this.val[o.hash] = o.url;
  },
  remove:function (hash){
    for(i=0;i<this.key.length;i++)
     {
      if(hash === this.key[i])
       {
         this.val[this.key[i]] = null;
         this.key.splice(i,1);
         return;
       }
     }
  },
  set:function (hash){
    for(i=0;i<this.key.length;i++)
     {
      if(hash === this.key[i])
       {
         this.current = i;
         return ;
       }
     }
  },
  getCurrent:function (){ return this.val[this.key[this.current]];},
  prev:function (){
    this.move("p");
    return this.val[this.key[this.current]];
  },  www.2cto.com
  next:function (){
    this.move("n");
    return this.val[this.key[this.current]];
  },
  move:function (direction)
  {
      if(direction=="n"&&this.current < this.key.length)
       {
        this.current++;
        return ;
       }
      if(direction=="p"&&this.current > 0)
       {
        this.current--;
        return ;
       }
  }
 };

 

作者:i_saw_you