javascript - 使用 SnapSvg 切换到触摸事件

标签 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
    });
}

谢谢

最佳答案

我们开始:

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();
    });

关于javascript - 使用 SnapSvg 切换到触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24369000/

相关文章:

javascript - 谷歌图表 API,带注释的时间轴 : properly setup several series and scales

javascript - 上一张图像完成后加载下一张图像

javascript - 解析ajax请求,返回页面为xml

javascript - 动画多边形点 snap.svg

javascript - Paintcode 和 Snap SVG

javascript - Snap.svg 拖动路径元素

javascript - 如何正确使用 JWT 和 Node

javascript - React + Flux 和服务端渲染? (同构 React + Flux)

javascript - 使用 Snap.svg 为多边形中的点设置动画

javascript - 尝试使用 snap.svg。 "Paper"对象不工作