jeudi 30 juin 2016

JavaScript iterate through items backwards

I am iterating through some photos using this code:

if (this.lightboxIndex < this.photos.length - 1) {
            this.lightboxIndex++;
          } else {
            this.lightboxIndex = 0;
          }
          this.lightboxSrc = this.photos[this.lightboxIndex].src;
        },

How can i iterate backwards through the same photos? Is this along the lines of what I need to do?

if(this.lightboxIndex < this.photos.length - 1){
            this.lightboxIndex--;
          } else {
            this.lightboxIndex = 0;
          }
          this.lightboxSrc = this.photos[this.lightboxIndex].src;
        },

Aucun commentaire:

Enregistrer un commentaire