jQuery Mobile 方向
jQuery Mobile orientationchange 事件
orientationchange 事件在用户垂直或水平旋转移动设备时被触发。

Mobile
如需使用 orientationchange 事件,请把它添加到 window 对象:
- $(window).on("orientationchange",function(){
- alert("方向已改变!");
- });
callback 函数可以设置一个参数,即 event 对象,它会返回移动设备的方向:"portrait" (设备被握持的方向是垂直的)或 "landscape" (设备被握持的方向是水平的):
实例
- $(window).on("orientationchange",function(event){
- alert("方向是:" + event.orientation);
- });
由于 orientationchange 事件与 window 对象绑定,我们能够使用 window.orientation 属性来,例如,设置不同样式以区分 portrait 和 landscape 视图:
实例
- $(window).on("orientationchange",function(){
- if(window.orientation == 0) // Portrait
- {
- $("p").css({"background-color":"yellow","font-size":"300%"});
- }
- else // Landscape
- {
- $("p").css({"background-color":"pink","font-size":"200%"});
- }
- });
提示:window.orientation 属性对 portrait 视图返回 0,对 landscape 视图返回 90 或 -90。
转载本站内容时,请务必注明来自W3xue,违者必究。