判断移动端还是pc端function
IsPC()
{
var
userAgentInfo = navigator.userAgent;
var
Agents =
new
Array(
"Android"
,
"iPhone"
,
"SymbianOS"
,
"Windows Phone"
,
"iPad"
,
"iPod"
);
var
flag =
true
;
for
(
var
v = 0; v < Agents.length; v++) {
if
(userAgentInfo.indexOf(Agents[v]) > 0) { flag =
false
;
break
; }
}
return
flag;
}
$(document).bind(touchEvents.touchstart,
function
(event) {
event.preventDefault();
});<br>
$(document).bind(touchEvents.touchmove,
function
(event) {
event.preventDefault();
});
$(document).bind(touchEvents.touchend,
function
(event) {
event.preventDefault();
});
var touchEvents = { touchstart: "touchstart", touchmove: "touchmove", touchend: "touchend", /** * @desc:判断是否pc设备,若是pc,需要更改touch事件为鼠标事件,否则默认触摸事件 */ initTouchEvents: function () { if (isPC()) { this.touchstart = "mousedown"; this.touchmove = "mousemove"; this.touchend = "mouseup"; } } };
若在pc上,则使用鼠标事件,在移动设备中,就使用触摸事件,就这么简单。