实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<link rel="stylesheet" href="https://apps.bdimg.com/libs/jquerymobile/1.4.2/jquery.mobile.min.css">
5
<script src="https://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
6
<script src="https://apps.bdimg.com/libs/jquerymobile/1.4.2/jquery.mobile.min.js"></script>
7
<script>
8
$(document).on("pageinit",function(event){
9
  $(window).on("orientationchange",function(){
10
    if(window.orientation == 0)
11
    {
12
      $("p").text("方向已经变为 portrait !").css({"background-color":"yellow","font-size":"300%"});
13
    }
14
    else
15
    {
16
      $("p").text("方向已经变为 landscape !").css({"background-color":"pink","font-size":"200%"});
17
    }
18
  });                   
19
});
20
</script>
21
</head>
22
<body>
23
24
<div data-role="page">
25
  <div data-role="header">
26
    <h1>orientationchange 事件</h1>
27
  </div>
28
29
  <div data-role="content">
30
    <p>请试着旋转您的设备!</p>
31
    <p><b>注释:</b>您必须使用移动设备或者移动模拟器来查看该事件的效果。</p>
32
  </div>
33
34
  <div data-role="footer">
35
    <h1>页脚文本</h1>
36
  </div>
37
</div> 
38
39
</body>
40
</html>
41