我需要使用 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/