js 鏈表,瀏覽圖片

 $.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]];
  },
  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 ;
       }
  }
 };
發佈了126 篇原創文章 · 獲贊 5 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章