From 42f34af27721991b40c8ec295c05d1198c7b7d60 Mon Sep 17 00:00:00 2001 From: "Toerd@480" Date: Thu, 24 Oct 2019 13:39:25 +0200 Subject: [PATCH] First try on apple fix horizontal scroll --- inc/js/main.js | 44 +++++++++++++++++++++++++++++++++++++++----- inc/js/zoom.js | 1 - 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/inc/js/main.js b/inc/js/main.js index 18f5acc..e09493c 100644 --- a/inc/js/main.js +++ b/inc/js/main.js @@ -16,6 +16,7 @@ function initialize() { let welcome = document.getElementById("welcome"); let exhibit = document.getElementById("exhibition"); let notice = Array.from(document.getElementsByClassName("arrow")); + let userAgent = window.navigator.userAgent; flyingText(welcome); document.addEventListener("click", (e) => { let overlay = document.getElementById("info-box"); @@ -31,11 +32,44 @@ function initialize() { } }); - // remove the indicator on enter - exhibit.addEventListener("mouseenter", () => { - notice[0].remove(); - notice[1].remove(); - }, {once: true}); + // Handle dummy dum dum Apple products >: + if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)) { + exhibit.addEventListener("scroll", (e) => { + e.preventDefault(); + }); + let startpos; + exhibit.addEventListener("touchmove", (e) => { + e.preventDefault(); + }); + + exhibit.addEventListener("touchstart", (e) => { + startpos = e.touches[0].clientX; + }); + + exhibit.addEventListener("touchend", (e) => { + let slide = startpos - e.changedTouches[0].clientX; + if (slide < -5 || slide > 5 ) { + doSlide(exhibit, slide); + } + }); + } + else { + remove the indicator on enter + exhibit.addEventListener("mouseenter", () => { + notice[0].remove(); + notice[1].remove(); + }, {once: true}); + } +} + +function doSlide(elem, dist) { + console.log(dist); + let hM = elem.scrollHeight; + let sT = elem.scrollTop; + if (dist < 0) + elem.scrollTop = (sT + dist > 0) ? sT + dist : 0; + else + elem.scrollTop = (sT + dist > hM) ? hM : sT + dist; } function handleThumb(overlay, elem) { diff --git a/inc/js/zoom.js b/inc/js/zoom.js index 9da2b5f..3b99857 100644 --- a/inc/js/zoom.js +++ b/inc/js/zoom.js @@ -7,7 +7,6 @@ * Version: 1.2 */ function zoom(factor, imgName) { - console.log("CALL:" + imgName); let winW = Math.max(document.documentElement.clientWidth, window.innerWidth); let img = document.getElementById(imgName); let magni = img.parentElement;