cubiq / iscroll

Smooth scrolling for the web
http://iscrolljs.com
MIT License
12.87k stars 3.8k forks source link

cannot got the correct e.clientX or e.screenX position info, maybe it's a bug, pls have a check. #1047

Open winkying opened 8 years ago

winkying commented 8 years ago

i thought the the "click" event maybe have a bug here in "iscroll.js" `me.click = function (e) { var target = e.target, ev;

    if ( !(/(SELECT|INPUT|TEXTAREA)/i).test(target.tagName) ) {
        ev = document.createEvent(window.MouseEvent ? 'MouseEvents' : 'Event');
        ev.initEvent('click', true, true);
        ev.view = e.view || window;
        ev.detail = 1;
        ev.screenX = target.screenX || 0;
        ev.screenY = target.screenY || 0;
        ev.clientX = target.clientX || 0;
        ev.clientY = target.clientY || 0;
        ev.ctrlKey = !!e.ctrlKey;
        ev.altKey = !!e.altKey;
        ev.shiftKey = !!e.shiftKey;
        ev.metaKey = !!e.metaKey;
        ev.button = 0;
        ev.relatedTarget = null;
        ev._constructed = true;
        target.dispatchEvent(ev);
    }
};`==>
var target = e.target,position,
            ev;

        if ( !(/(SELECT|INPUT|TEXTAREA)/i).test(target.tagName) ) {
            if(e.type === 'mouseup'){
                position = e;
            }else if(e.type === 'touchend'){
                position = e.changedTouches[0];
            }
             ev = new MouseEvent('click',{
                     'view':window,
                     'detail':1,
                     'bubbles': true,
                     'cancelable': true,
                     'screenX':position.screenX || 0,
                     'screenY':position.screenY || 0,
                     'clientX':position.clientX || 0,
                     'clientY':position.clientY || 0,
                     'ctrlKey':!!e.ctrlKey,
                     'altKey':!!e.altKey,
                     'shiftKey':!!e.shiftKey,
                     'metaKey':!!e.metaKey,
                     'button':0,
                     'relatedTarget':null
            });