Skip to content Skip to sidebar Skip to footer

Detect Mobile Device Rotation With Jquery

I am searching for a jQuery-plugin or Javascript-library that detects the rotation of a device in degrees, not just orientation, using the G-sensor. I know it can be done - check h

Solution 1:

you can use jquery mobile lib orientationchange event.

$(window).on("orientationchange",function(event){
    var x = event.beta,  // -180 to 180
        y = event.gamma, // -90 to 90
        z = event.alpha; // 0 to 360
});

without jQuery:

window.addEventListener('orientationchange', function(event){
    var x = event.beta,  // -180 to 180
        y = event.gamma, // -90 to 90
        z = event.alpha; // 0 to 360
});

also try this..

if (window.DeviceOrientationEvent) {
    window.addEventListener('deviceorientation', function(event){
    });
}

Post a Comment for "Detect Mobile Device Rotation With Jquery"