Summary Files Commits Branches @commit @diff @stats
path: root / src / scripts
diff options
context:
space:
mode:
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..b1ca7cf
--- /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.classList.contains('clicked-image')) {
+ window.scrollTo(0, scrollPosition);
+ scrollPosition = 0;
+ }
+}
+
+const images = document.getElementsByTagName('img');
+
+for (const image of images) {
+ if (image.alt !== '🔗') {
+ image.onclick = clickToView;
+ }
+}