Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preload did not take into account the wrapAround option #760

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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