Skip to content

Commit

Permalink
Wait for load
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasLacerdaUX committed Feb 2, 2023
1 parent b362487 commit d85ed30
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions assets/magnify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ function createOverlay(image) {
overlay = document.createElement('div');
overlay.setAttribute('class', 'image-magnify-full-size');
overlay.setAttribute('aria-hidden', 'true');
overlay.style.backgroundImage = `url('${image.src}')`;
image.parentElement.insertBefore(overlay, image);

const bgImg = new Image();
bgImg.onload = () => {
overlay.style.backgroundImage = `url('${image.src}')`;
image.parentElement.insertBefore(overlay, image);
}
bgImg.src = image.src;
return overlay;
};

Expand Down

0 comments on commit d85ed30

Please sign in to comment.