0

What would be the best approach to detect whenever the user changes the orientation of his phone. I am talking for a mobile site not for a native app.

Thanks,

silkAdmin
  • 4,640
  • 10
  • 52
  • 83

1 Answers1

1
window.addEventListener('onorientationchange', function () {
    if (window.orientation == -90) {
        //do stuff
    }
    if (window.orientation == 90) {
        //do stuff
    }
    if (window.orientation == 0) {
        //do stuff
    }
}, true);
Mild Fuzz
  • 29,463
  • 31
  • 100
  • 148