Summary Files Commits Branches @commit @diff @stats
path: root / src / scripts
diff options
context:
space:
mode:
Commitbc5188fc21a825f4849139cd9888b0476fd34a99 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-02-20 13:09:15 +0200
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-02-20 13:09:15 +0200
Files067f96fc807cab3269d54fa4874ba79292912e3b /src/scripts
syndamia.com-bc5188fc21a825f4849139cd9888b0476fd34a99.tar
syndamia.com-bc5188fc21a825f4849139cd9888b0476fd34a99.tar.gz
syndamia.com-bc5188fc21a825f4849139cd9888b0476fd34a99.zip
Parentd00c9b47607d57512ebe90ce0ce98bdb3834dd9c (diff)
Implemented click to zoom on images
1 files changed, 24 insertions, 0 deletions
-rw-r--r--src/scripts/image-show.js24
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;
+ }
+}