From 70b46f6c2c6c34d7f89a2ab0695f68b0dfaf3095 Mon Sep 17 00:00:00 2001 From: anapnoe <124302297+anapnoe@users.noreply.github.com> Date: Sun, 2 Apr 2023 07:16:14 +0300 Subject: [PATCH] enchantment move sliders by swipe for mobile #29 --- javascript/ui.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/javascript/ui.js b/javascript/ui.js index eafcb33c..0633d076 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -955,17 +955,26 @@ onUiUpdate(function(){ comp_range.parentElement.append(clone_range); comp_range.classList.add("hidden"); - clone_range.addEventListener('input', function (e) { + clone_range.addEventListener('input', function (e) { clone_num.value = e.target.value; - }) - + }) clone_range.addEventListener('change', function (e) { elem.value = clone_range.value; updateInput(elem); }) clone_num.addEventListener('input', function (e) { clone_range.value = e.target.value; - }) + }) + + const rect = clone_range.getBoundingClientRect(); + const xoffset = (rect.left + window.scrollX); + clone_range.addEventListener('touchmove', function(e) { + e.preventDefault(); + let percent = parseInt(((e.touches[0].pageX - xoffset) / this.offsetWidth) * 10000) / 10000; + clone_range.value = ( percent * (this.max - this.min)) + parseFloat(this.min); + clone_num.value = clone_range.value; + }); + } } function ui_input_focus_handler(e){