Skip to content

Commit

Permalink
Add lazy loading for shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
utensil committed Aug 19, 2024
1 parent 0828e15 commit e4f726e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
8 changes: 8 additions & 0 deletions assets/images/3d-cube-scan-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 11 additions & 3 deletions assets/shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ embeded_shaders.forEach((element) => {
let shader = element.textContent;
element.textContent = '';

resolveIncludesAsync(shader).then((shader) => {
const renderer = ImageEffectRenderer.createTemporary(element, shader, options);
});
element.classList.add('lazy-loading');

let handleMouseOver = (event) => {
resolveIncludesAsync(shader).then((shader) => {
element.classList.remove('lazy-loading');
const renderer = ImageEffectRenderer.createTemporary(element, shader, options);
element.removeEventListener('mouseover', handleMouseOver);
});
};

element.addEventListener('mouseover', handleMouseOver);
});
23 changes: 23 additions & 0 deletions assets/uts-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,30 @@ button#langblock-toggle {
filter: invert(0.85);
}

@keyframes breathing {
0% {
opacity: 0;
}

50% {
opacity: 0.3;
}

100% {
opacity: 0;
}
}

.embeded-shader {
color: transparent;
padding: 1em 1em 1em 1em;
}

.embeded-shader.lazy-loading {
height: 30ex;
background-image: url(./images/3d-cube-scan-svgrepo-com.svg);
background-repeat: no-repeat;
background-position: center;
background-size: 20%;
animation: breathing 2s ease-out infinite;
}

0 comments on commit e4f726e

Please sign in to comment.