Copy codeThe Code is as follows:
Var $ horizontal = $ ('. horizontal_screen'); // you can customize the horizontal screen mode.
Var $ document = $ (document );
Var preventDefault = function (e ){
E. preventDefault ();
};
Var touchstart = function (e ){
$ Document. on ('touchstart touchmove ', preventDefault );
};
Var touchend = function (e ){
$ Document. off ('touchstart touchmove ', preventDefault );
};
Function listener (type ){
If ('add' = type ){
// Portrait Mode
$ Horizontal. addClass ('hide ');
$ Document. off ('touchstart', touchstart );
$ Document. off ('touchend', touchend );
} Else {
// Landscape mode
$ Horizontal. removeClass ('hide ');
$ Document. on ('touchstart', touchstart );
$ Document. on ('touchend', touchend );
}
}
Function orientationChange (){
Switch (window. orientation ){
// Portrait Mode
Case 0:
Case 180:
Listener ('add ');
Break;
// Landscape mode
Case-90:
Case 90:
Listener ('delete ');
Break;
}
}
$ (Window). on ("onorientationchange" in window? "Orientationchange": "resize", orientationChange );
$ Document. ready (function (){
// Enter the interface in Landscape mode, prompting that only portrait screens are supported
If (window. orientation = 90 | window. orientation =-90 ){
Listener ('delete ');
}
});