From bc5188fc21a825f4849139cd9888b0476fd34a99 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 20 Feb 2022 13:09:15 +0200 Subject: Implemented click to zoom on images --- src/_footer.html | 2 ++ src/scripts/image-show.js | 24 ++++++++++++++++++++++++ src/styles.css | 23 +++++++++++++++++++---- 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 src/scripts/image-show.js (limited to 'src') diff --git a/src/_footer.html b/src/_footer.html index 32da16f..b498d55 100644 --- a/src/_footer.html +++ b/src/_footer.html @@ -18,6 +18,8 @@ ssg by Roman Zolotarev lowdown by Kristaps Dzonsons + + diff --git a/src/scripts/image-show.js b/src/scripts/image-show.js new file mode 100644 index 0000000..1683107 --- /dev/null +++ b/src/scripts/image-show.js @@ -0,0 +1,24 @@ +let scrollPosition = 0; + +function clickToView() { + if (scrollPosition === 0) { + scrollPosition = window.scrollY; + window.scrollTo(0, 0); + } + + this.classList.toggle('clicked-image'); + document.body.classList.toggle('body-on-clicked-image'); + + if (this.className.length === 0) { + window.scrollTo(0, scrollPosition); + scrollPosition = 0; + } +} + +const images = document.getElementsByTagName('img'); + +for (const image of images) { + if (image.alt !== '🔗') { + image.onclick = clickToView; + } +} diff --git a/src/styles.css b/src/styles.css index 5ecf230..abe7006 100644 --- a/src/styles.css +++ b/src/styles.css @@ -58,10 +58,6 @@ img { image-rendering: crisp-edges; } -img:hover { - image-rendering: pixelated; -} - img, hr { border: 1px solid black; } @@ -360,6 +356,25 @@ code span { color: #afaf00; } +/* Script specific styling */ + +.clicked-image { + position: absolute; + width: 100vw; + height: 100vh; + max-width: none !important; + max-height: none !important; + border: none; + object-fit: contain; + left: 0; + top: 0; + padding: 1em; +} + +.body-on-clicked-image { + overflow: hidden; +} + /* OpenSans font */ @font-face { -- cgit v1.3.1-26-gb76a