diff --git a/supply.html b/supply.html index 7bba1af..9d82f79 100644 --- a/supply.html +++ b/supply.html @@ -5925,20 +5925,42 @@ setupAutoSave(); } + // 存储触摸事件监听器的引用 + let touchMoveListener = null; + // 防止iOS页面拖动的函数 function preventiOSScrolling() { - // 阻止触摸事件的默认行为,防止页面滚动 - document.addEventListener('touchmove', function(e) { + // 先移除之前的监听器,避免重复添加 + if (touchMoveListener) { + document.removeEventListener('touchmove', touchMoveListener, { passive: false }); + } + + // 定义触摸事件监听器 + touchMoveListener = function(e) { + // 只阻止页面滚动,不阻止模态框内的滚动 + const target = e.target; + const createSupplyModal = document.getElementById('createSupplyModal'); + + // 如果触摸目标在模态框内,允许滚动 + if (createSupplyModal && createSupplyModal.contains(target)) { + return; + } + + // 阻止页面滚动 e.preventDefault(); - }, { passive: false }); + }; + + // 添加触摸事件监听器 + document.addEventListener('touchmove', touchMoveListener, { passive: false }); } // 恢复iOS页面滚动的函数 function restoreiOSScrolling() { // 移除触摸事件监听器,恢复页面滚动 - document.removeEventListener('touchmove', function(e) { - e.preventDefault(); - }, { passive: false }); + if (touchMoveListener) { + document.removeEventListener('touchmove', touchMoveListener, { passive: false }); + touchMoveListener = null; + } } // 隐藏创建货源模态框