Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 16:50:391419browse
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');
}
});
Statement:
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