diff --git a/images/f16-main-landing-gear-spritesheet.avif b/images/f16-main-landing-gear-spritesheet.avif new file mode 100644 index 0000000..1d0f3a4 Binary files /dev/null and b/images/f16-main-landing-gear-spritesheet.avif differ diff --git a/images/gingerbread-spritesheet.avif b/images/gingerbread-spritesheet.avif new file mode 100644 index 0000000..2806a6b Binary files /dev/null and b/images/gingerbread-spritesheet.avif differ diff --git a/index.php b/index.php index 8bab178..37bfd79 100644 --- a/index.php +++ b/index.php @@ -13,6 +13,60 @@ function onClickArrow() { return new bootstrap.Tooltip(tooltipTriggerEl); }); }); + document.addEventListener('DOMContentLoaded', function() { + var animatedSpriteElements = document.querySelectorAll('.animated-sprite'); + + animatedSpriteElements.forEach(function(animatedSpriteElement) { + setAspectRatio(animatedSpriteElement); + setBackgroundSize(animatedSpriteElement); + + window.addEventListener('scroll', function() { + handleScroll(animatedSpriteElement); + }); + handleScroll(animatedSpriteElement); + }); + }); + + function setAspectRatio(element) { + var frameWidth = parseInt(element.getAttribute('data-frame-width'), 10); + var frameHeight = parseInt(element.getAttribute('data-frame-height'), 10); + + if (frameWidth && frameHeight) { + var aspectRatioPercentage = (frameHeight / frameWidth) * 100; + element.style.setProperty('--bs-aspect-ratio', aspectRatioPercentage + '%'); + } + } + + function setBackgroundSize(element) { + var frameCount = parseInt(element.getAttribute('data-frame-count'), 10); + var framesPerRow = parseInt(element.getAttribute('data-frames-per-row'), 10) || frameCount; + + var backgroundSizePercentage = framesPerRow * 100; + element.style.backgroundSize = backgroundSizePercentage + '% auto'; + } + + function handleScroll(element) { + var frameCount = parseInt(element.getAttribute('data-frame-count'), 10); + var elementRect = element.getBoundingClientRect(); + var elementTopPosition = elementRect.top; + var viewportHeight = window.innerHeight; + + var scrollProgress = (elementTopPosition - viewportHeight * 0.2) / (viewportHeight * 0.5); + scrollProgress = 1 - Math.max(0, Math.min(1, scrollProgress)); + var currentFrame = Math.floor(scrollProgress * (frameCount - 1)); + + updateBackgroundPosition(element, currentFrame); + } + + function updateBackgroundPosition(element, frame) { + var frameCount = parseInt(element.getAttribute('data-frame-count'), 10); + var framesPerRow = parseInt(element.getAttribute('data-frames-per-row'), 10) || frameCount; + + var backgroundPositionX = -(frame % framesPerRow) * 100; + var backgroundPositionY = -Math.floor(frame / framesPerRow) * 100; + + element.style.backgroundPosition = backgroundPositionX + '% ' + backgroundPositionY + '%'; + }
@@ -67,6 +121,44 @@ function onClickArrow() { +
+ +
+
+
+
+ +
+

+ +
+
+ +
+ +
+
+
+
+ +
+

+ +
+
+
Screenshot 3