orientationchange event
添加的版本:1.0
说明:设备纵向/横向事件
-
jQuery( window ).on( "orientationchange", function( event ) { ... } )
event object 上的其他属性:
-
orientation类型:String设备的新方向。可能的值为
"portrait"
和"landscape"
。
-
jQuery Mobile orientationchange
事件在设备方向改变时触发,无论是垂直还是水平转动设备。当绑定到此事件时,回调函数具有事件对象。事件对象包含一个等于 "portrait"
或 "landscape"
的 orientation
属性。
请注意,当本机不支持 orientationchange
或 $.mobile.orientationChangeEnabled
设置为 false
时,我们会绑定到浏览器的调整大小事件。
方向改变时机
orientationchange
事件与客户端高度和宽度变化相关的时间在浏览器之间是不同的,尽管当前的实现将为您提供从 window.orientation
派生的 event.orientation
的正确值。这意味着如果您的绑定依赖于高度和宽度值,您可能希望与 $.mobile.orientationChangeEnabled = false
一起禁用 orientationChange
以让后备调整大小代码触发您的绑定。
例子:
从您的定向设备访问它以查看它的实际效果!
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>orientationchange demo</title>
<link rel="stylesheet" href="//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.css">
<script src="//code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.js"></script>
</head>
<body>
<h1 id="orientation">orientationchange Not Supported on this Device.</h1>
<script>
// Bind an event to window.orientationchange that, when the device is turned,
// gets the orientation and displays it to on screen.
$( window ).on( "orientationchange", function( event ) {
$( "#orientation" ).text( "This device is in " + event.orientation + " mode!" );
});
// You can also manually force this event to fire.
$( window ).orientationchange();
</script>
</body>
</html>
演示:
相关用法
- JQuery outerWidth()用法及代码示例
- JQuery one()用法及代码示例
- JQuery odd()用法及代码示例
- JQuery off()用法及代码示例
- JQuery offset()用法及代码示例
- JQuery offsetParent()用法及代码示例
- JQuery on()用法及代码示例
- JQuery outerHeight()用法及代码示例
- JQuery Mobile Popup initSelector用法及代码示例
- JQuery Mobile Collapsibleset disabled用法及代码示例
- JQuery UI Datepicker prevText用法及代码示例
- JQuery ajaxError()用法及代码示例
- JQuery Mobile Selectmenu defaults用法及代码示例
- JQuery UI Tabs event用法及代码示例
- JQuery UI Selectable appendTo用法及代码示例
- JQuery UI :focusable Selector用法及代码示例
- JQuery UI Selectmenu disabled用法及代码示例
- JQuery UI Button classes用法及代码示例
- JQuery .jquery用法及代码示例
- JQuery .scroll()用法及代码示例
- JQuery UI Draggable snapMode用法及代码示例
- JQuery each()用法及代码示例
- JQuery Mobile Toolbar hide用法及代码示例
- JQuery UI Tabs option用法及代码示例
- JQuery UI Buttonset widget用法及代码示例
注:本文由纯净天空筛选整理自jquerymobile.com大神的英文原创作品 orientationchange event。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。