Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/js/lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,18 @@

// Preload previous and next images in set.
Lightbox.prototype.preloadNeighboringImages = function() {
if (this.album.length > this.currentImageIndex + 1) {
var preloadNext = new Image();
preloadNext.src = this.album[this.currentImageIndex + 1].link;
}
if (this.currentImageIndex > 0) {
var preloadPrev = new Image();
preloadPrev.src = this.album[this.currentImageIndex - 1].link;
var indexes = [ this.currentImageIndex - 1, this.currentImageIndex + 1 ];
for (var i = 0; i < 2; i++) {
var index = indexes[i];
if (index >= this.album.length) {
if (!this.options.wrapAround) continue;
index = 0;
} else if (index < 0) {
if (!this.options.wrapAround) continue;
index = this.album.length - 1;
}
var preload = new Image();
preload.src = this.album[index].link;
}
};

Expand Down