From 14eebe303560776bf1e0b141ed5ee4d55db5fa5e Mon Sep 17 00:00:00 2001 From: sight <1453017105@qq.com> Date: Thu, 14 Dec 2023 21:01:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20colorpicker=20=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E7=AB=AF=E4=BA=8B=E4=BB=B6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/colorpicker.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/modules/colorpicker.js b/src/modules/colorpicker.js index 46b9d6cb..e2c3c794 100644 --- a/src/modules/colorpicker.js +++ b/src/modules/colorpicker.js @@ -567,6 +567,32 @@ layui.define(['jquery', 'lay'], function(exports){ change(hsb.h, hsb.s, hsb.b, a); }) }); + + if(!lay.touchEventsSupported()) return; + // 触摸事件模拟 + layui.each([ + {elem: side, eventType: 'click'}, + {elem: alphacolor, eventType: 'click'}, + {elem: basis, eventType: 'mousedown'} + ], function(i, obj){ + lay.touchSwipe(obj.elem, { + onTouchMove: function(e){ + touchHandler(e, obj.eventType) + } + }) + }) + + function touchHandler(event, eventType) { + var pointer = event.touches[0]; + var simulatedEvent = document.createEvent("MouseEvent"); + + simulatedEvent.initMouseEvent(eventType, + true, true, window, 1, + pointer.screenX, pointer.screenY,pointer.clientX, pointer.clientY, + false, false, false, false, 0, null + ); + pointer.target.dispatchEvent(simulatedEvent); + } }; //颜色选择器hsb转换