HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
When the user vertically or horizontally rotating mobile device, trigger change of direction (orientationchange) event.
To use the change of direction (orientationchange) event, please attach it to the window object:
$(window).on("orientationchange",function(){ alert("方向有改变!"); });
Callback function takes one parameter, event objects, return the direction of the mobile device: "Portrait" (device remains in a vertical position) or "horizontal" (device remains in a horizontal position):
Since the change of direction (orientationchange) bind events to the window object, we can use window.orientation property to set different styles to distinguish vertical and horizontal view:
window.orientation property returns 0 for portrait view, landscape view for a return to 90 or -90. |