PC 端與移動端的判斷(判斷是否支持touch事件)

方法一:

判斷是否支持觸屏:

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";
}



發佈了4 篇原創文章 · 獲贊 2 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章