Home > Web Front-end > JS Tutorial > js determine horizontal and vertical screen and disable browser slider example_javascript skills

js determine horizontal and vertical screen and disable browser slider example_javascript skills

WBOY
Release: 2016-05-16 16:50:39
Original
1445 people have browsed it
Copy code The code is as follows:

var $horizontal = $('.horizontal_screen'); //Can Customize landscape mode prompt style
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('remove');
break;
}
}

$(window).on("onorientationchange" in window ? "orientationchange" : "resize", orientationChange);

$document.ready(function(){
//In landscape mode Entering the interface, the prompt only supports vertical screen
if(window.orientation == 90 || window.orientation == -90){
listener('remove');
}
});
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template