Skip to content

Commit

Permalink
Fix background flicker on switch preview image
Browse files Browse the repository at this point in the history
  • Loading branch information
pkong-ds committed Aug 27, 2024
1 parent 9fda97d commit cc4da57
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion public/scripts/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,15 @@ function main() {
imageUploads[i].isSuccessState &&
imageUploads[i].ulid == window.viewModel.selectedPreviewImageULID
) {
imageContainer.style.backgroundImage = `url(${imageUploads[i].previewUrl})`;
// create a new Image object
var img_tag = new Image();
const url = imageUploads[i].previewUrl
// when preload is complete, apply the image to the div
img_tag.onload = function () {
imageContainer.style.backgroundImage = 'url(' + url + ')';
}
// setting 'src' actually starts the preload
img_tag.src = url;
}
}
},
Expand Down

0 comments on commit cc4da57

Please sign in to comment.