<h1>JavaScript Event: orientationchange</h1>
<p>
Silahkan putar device atau smartphone untuk melihat hasilnya:
</p>
<div id="demo"></div>
document.getElementById("demo").innerHTML = screen.orientation.type; //Mengetahui orientasi awal
window.addEventListener("orientationchange", function() {
if ( window.orientation == 0 || window.orientation == 180) {
document.getElementById("demo").innerHTML = "MODE PORTRAIT";
} else {
document.getElementById("demo").innerHTML = "MODE LANDSCAPE";
}
}, false);
HTML
CSS
JS