课程表

jQuery Mobile 教程

jQuery Mobile 列表

jQuery Mobile 表单

jQuery Mobile 主题

jQuery Mobile 事件

jQuery Mobile 实例

jQuery Mobile 参考手册

工具箱
速查手册

jQuery Mobile 方向

当前位置:免费教程 » 移动开发 » jQuery Mobile

jQuery Mobile orientationchange 事件

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

Mobile

Mobile

如需使用 orientationchange 事件,请把它添加到 window 对象:

  1. $(window).on("orientationchange",function(){
  2. alert("方向已改变!");
  3. });

callback 函数可以设置一个参数,即 event 对象,它会返回移动设备的方向:"portrait" (设备被握持的方向是垂直的)或 "landscape" (设备被握持的方向是水平的):

实例

  1. $(window).on("orientationchange",function(event){
  2. alert("方向是:" + event.orientation);
  3. });

亲自试一试

由于 orientationchange 事件与 window 对象绑定,我们能够使用 window.orientation 属性来,例如,设置不同样式以区分 portrait 和 landscape 视图:

实例

  1. $(window).on("orientationchange",function(){
  2. if(window.orientation == 0) // Portrait
  3. {
  4. $("p").css({"background-color":"yellow","font-size":"300%"});
  5. }
  6. else // Landscape
  7. {
  8. $("p").css({"background-color":"pink","font-size":"200%"});
  9. }
  10. });

亲自试一试

提示:window.orientation 属性对 portrait 视图返回 0,对 landscape 视图返回 90 或 -90。

转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号