js判断是否是移动端(触摸屏)或者是PC

js代码:

console.log("ontouchstart" in window);

 手机web浏览器,chrome模拟手机、手机APP会返回true,

pc端(非手机模拟状态下)返回false

 

 所以:一种事件的处理方法:


    var isTouch = ("ontouchstart" in window) ? true : false;
    var touchStartEvt = isTouch ? "touchstart" : "mousedown";
    var touchMoveEvt = isTouch ? "touchmove" : "mousemove";
    var touchEndEvt = isTouch ? "touchend" : "mouseup";
    var transitionEndEvt = vendorPrefix + "TransitionEnd";

posted @ 2015-12-24 15:22  哈姆PP  阅读(2938)  评论(0编辑  收藏  举报