diff --git a/www/image-modal.js b/www/image-modal.js new file mode 100644 index 0000000..bdd696c --- /dev/null +++ b/www/image-modal.js @@ -0,0 +1,62 @@ +const images = document.getElementsByClassName('project-image'); + +for (const image of images) { + const modal = image.querySelector('.modal') + const close = image.querySelector('.close') + const lazy_image = image.querySelector('.lazy-image') + const zoom = modal.querySelector('input') + + // for pan + let grabbed = false; + let startX = 0; + let startY = 0; + + // for zoom + let clickX = 0; + let clickY = 0; + let initW = lazy_image.clientWidth; + let initH = lazy_image.clientHeight; + + // pan the image + lazy_image.addEventListener('mouseleave', () => {grabbed = false;}); + lazy_image.addEventListener('mouseup', () => { + grabbed = false; + }); + lazy_image.addEventListener('mousedown', (e) => { + grabbed = true; + startX = modal.scrollLeft + e.pageX; + startY = modal.scrollTop + e.pageY; + + // set stuff for zoom + clickX = e.clientX - lazy_image.offsetLeft; + clickY = e.clientY - lazy_image.offsetTop; + initW = lazy_image.clientWidth; + initH = lazy_image.clientHeight; + }); + lazy_image.addEventListener('mousemove', (e) => { + if(!grabbed) return; + modal.scrollLeft = startX - e.pageX; + modal.scrollTop = startY - e.pageY; + }); + + // unzoom on close + close.addEventListener('click', () => { + zoom.checked = false; + }); + + // zoom to click target + zoom.addEventListener('change', e => { + if (zoom.checked) { + zoom_factor = Math.max( + lazy_image.clientWidth / initW, + lazy_image.clientHeight / initH + ); + console.log(zoom_factor); + x = clickX * zoom_factor - (window.innerWidth / 2); + y = clickY * zoom_factor - (window.innerHeight / 2); + console.log('zoom 2 ' + x + ', ' + y); + modal.scrollLeft = x; + modal.scrollTop = y; + } + }) +} \ No newline at end of file diff --git a/www/img/modal-close.svg b/www/img/modal-close.svg new file mode 100644 index 0000000..4537467 --- /dev/null +++ b/www/img/modal-close.svg @@ -0,0 +1,63 @@ + + + + diff --git a/www/index.html b/www/index.html index f55297c..4b840ff 100644 --- a/www/index.html +++ b/www/index.html @@ -55,7 +55,7 @@
An end-to-end encrypted client/server messaging application.
@@ -66,7 +66,30 @@ click image to view in full resolution