为什么80%的码农都做不了架构师?>>>
ontouchend
通过判断是否支持触摸,支持触摸的设备大都都是移动端。if ('ontouchend' in document.body) {
// 移动端
}
这里为什么用
ontouchend
的原因是,
ontouchend
相对于
ontouchstart
、
ontouchmove
、
ontouchcancel
来说长度最短。
userAgent
通过判断用户代理字符串中是否包含mobile
关键字。
if (/mobile/i.test(navigator.userAgent)) {
// 移动端
}