Page 129 - JqueryMobile_Manual
P. 129
129
Orientationchange event - Alert orientation
tryjqmob_events_orientationchange.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
$(document).on("pagecreate",function(event){
$(window).on("orientationchange",function(event){
alert("Orientation changed to: " + event.orientation);
});
});
</script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>The orientationchange Event</h1>
</div>
<div data-role="main" class="ui-content">
<p>Try to rotate your device!</p>
<p><b>Note:</b> You must use a mobile device, or a mobile emulator to see the effect of this
event.</p>
</div>
<div data-role="footer">
<h1>Footer Text</h1>
</div>
</div>
</body>
</html>
Orientationchange event - Set different styles for portrait and landscape
tryjqmob_events_orientationchange2.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
$(document).on("pagecreate",function(event){
$(window).on("orientationchange",function(){
if(window.orientation == 0)
{
$("p").text("The orientation has changed to portrait!").css({"background-color":"yellow","font-
size":"300%"});
}