您的位置:首页 > 移动开发

PC 端与移动端的判断(判断是否支持touch事件)

2015-10-10 09:28 525 查看
方法一:

判断是否支持触屏:

window.onload = function(){
if(document.hasOwnProperty("ontouchstart")){
alert(浏览器支持触屏");
}else{
alert("浏览器不支持触屏");
}
}
注:此方法在google的移动端模拟器上不适用;

方法二:

if("ontouchstart" in window){
startEvt = "touchstart";
moveEvt = "touchmove";
endEvt = "touchend";
}else{
startEvt = "mousedown";
moveEvt = "mousemove";
endEvt = "mouseup";
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: