JavaScript code used to determine the horizontal and vertical screens and to disable the browser slide entries

Source: Internet
Author: User

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 ');
}
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.