diff options
Implemented click to zoom on images
3 files changed, 45 insertions, 4 deletions
| -rw-r--r-- | src/_footer.html | 2 | ||||
| -rw-r--r-- | src/scripts/image-show.js | 24 | ||||
| -rw-r--r-- | src/styles.css | 23 |
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 @@ <a href="https://www.romanzolotarev.com/ssg.html" target="_blank" class="link-tab">ssg by Roman Zolotarev</a> <a href="https://kristaps.bsd.lv/lowdown/" target="_blank" class="link-tab">lowdown by Kristaps Dzonsons</a> </nav> + + <script type="text/javascript" src="/scripts/image-show.js"></script> </body> </html> 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 { |