diff --git a/packages/vant-touch-emulator/index.js b/packages/vant-touch-emulator/index.js index e35532983..b1f754978 100644 --- a/packages/vant-touch-emulator/index.js +++ b/packages/vant-touch-emulator/index.js @@ -78,36 +78,33 @@ function TouchList() { return touchList; } -/** - * Simple trick to fake touch event support - * this is enough for most libraries like Modernizr and Hammer - */ -function fakeTouchSupport() { - var objs = [window, document.documentElement]; - var props = ['ontouchstart', 'ontouchmove', 'ontouchcancel', 'ontouchend']; - for (var o = 0; o < objs.length; o++) { - for (var p = 0; p < props.length; p++) { - if (objs[o] && objs[o][props[p]] === undefined) { - objs[o][props[p]] = null; - } - } - } -} /** * only trigger touches when the left mousebutton has been pressed * @param touchType * @returns {Function} */ + + +var initiated = false; function onMouse(touchType) { return function(ev) { // prevent mouse events - if (ev.which !== 1) { - return; + if (ev.type === 'mousedown') { + initiated = true; } + if (ev.type === 'mouseup') { + initiated = false; + } + + if (ev.type === 'mousemove' && !initiated) { + return + } + + // The EventTarget on which the touch point started when it was first placed on the surface, // even if the touch point has since moved outside the interactive area of that element. // also, when the target doesnt exist anymore, we update it @@ -173,8 +170,6 @@ function getActiveTouches(mouseEv) { * TouchEmulator initializer */ function TouchEmulator() { - fakeTouchSupport(); - window.addEventListener('mousedown', onMouse('touchstart'), true); window.addEventListener('mousemove', onMouse('touchmove'), true); window.addEventListener('mouseup', onMouse('touchend'), true);