別の古いトピックですが、まだ関連があります-デバイスにモーションセンサーがあるかどうかを確認します。多くのラップトップではありませんが、最新のスマートフォンとタブレットはすべて搭載されているため、ラップトップユーザーはわずかに多くのバッテリーを使用して生活できます-
jQuery:
if (window.DeviceOrientationEvent) {
$(window).one("devicemotion", function(event) {
if (event.originalEvent.acceleration
&& event.originalEvent.acceleration.x !== null) { // Chrome fakes it on desktop
isMobile = true;
}
});
}
プレーン Javascript:
if (window.DeviceOrientationEvent) {
window.ondevicemotion = function(event) {
if (event.acceleration
&& event.acceleration.x !== null) { // Chrome fakes it on desktop
window.ondevicemotion = null;
isMobile = true;
}
};
}