Maison  >  Article  >  interface Web  >  js détermine l'écran horizontal et vertical et désactive les compétences du curseur de navigateur example_javascript

js détermine l'écran horizontal et vertical et désactive les compétences du curseur de navigateur example_javascript

WBOY
WBOYoriginal
2016-05-16 16:50:391390parcourir
Copier le code Le code est le suivant :

var $horizontal = $('.horizontal_screen'); //Peut personnaliser le style d'invite du mode paysage
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 écouteur(type){
if('add' == type){
//Mode portrait
$horizontal.addClass(' hide');
$document.off('touchstart', touchstart);
$document.off('touchend', touchend);
}else{
//mode paysage
$horizontal.removeClass('hide');
$document.on('touchstart', touchstart);
$document.on('touchend', touchend); >function orientationChange(){
switch(window.orientation) {
//Mode portrait
case 0 :
case 180 :
listener('add');
break;
//Mode paysage
case -90 :
case 90 :
listener('remove');
break;
}

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

$document.ready(function(){
//En mode paysage En entrant dans l'interface, l'invite ne prend en charge que l'écran vertical
if(window.orientation == 90 || window.orientation == -90){
listener('remove');
}
}); >
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn