切换到使用SnapSvg触摸事件

时间:2014-06-23 14:52:43

标签: javascript snap.svg

我需要使用Snap SVG为我的网站使用触摸屏触摸事件和鼠标事件。

我有鼠标事件:

_Button.mousedown(function(){
    // Do Stuff
});

如何轻松切换到触摸事件,例如' touchstart'当我的用户来自平板电脑?

我不想复制代码,并检查它是否是触摸屏,就像有20倍*这样的代码:

_Button.mousedown(function(){
    // Do Stuff
});

if ( touchSreenFlag === true) {
    _Button.mousedown(function(){
        // Do Stuff
    });
}

THX

1 个答案:

答案 0 :(得分:1)

我们走了:

SVGTHING.mouseup(function(e){

        if (e.type === 'touchend') {
            // Stop propagation : on touch devices the first click will be used and not the second.
            e.stopPropagation();
            e.preventDefault();
        }

        do_stuff();
    });