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

Smooth loading of fullsize images #250

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
31 changes: 29 additions & 2 deletions ee_site/static/src/js/dynamic_fill_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,39 @@ const roundSize = (size) => {
**/
const assignDynamicSrc = (image) => {
if (!image.dataset.imageId) return;

// compute proper size image url
const width = roundSize(image.clientWidth);
const height = roundSize(image.clientHeight);
const newSrc = `${domainWithProtocol}/rendition/${image.dataset.imageId}/${width}/${height}/`;
if (newSrc != image.src) {
image.src = newSrc;
if (newSrc == image.src) return;

// create clone to cover image during src change
const clonedImage = image.cloneNode();
clonedImage.classList.remove('dynamic');
clonedImage.style.transition = "opacity 0.3s";
if (image.nextSibling) {
image.parentNode.insertBefore(clonedImage, image.nextSibling);
} else {
image.parentNode.appendChild(clonedImage);
}

// hide original image
image.style.opacity = 0;

// load proper size image into original img tag
const onloaded = () => {
// show image
image.style.opacity = clonedImage.style.opacity;

// delete cover image
clonedImage.style.opacity = 0;
setTimeout(() => clonedImage.remove(), 1000);

image.removeEventListener('load', onloaded);
};
image.addEventListener('load', onloaded);
image.src = newSrc;
};

/**
Expand Down
4 changes: 4 additions & 0 deletions ee_site/static/src/scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@
width: 100%;
z-index: -1;
}

img.dynamic {
transition: opacity 0.3s;
}