国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

js判斷橫豎屏及禁止瀏覽器滑動條示例

2019-11-20 20:46:13
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

var $horizontal = $('.horizontal_screen') ; //可自定義橫屏模式提示樣式
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){
//豎屏模式
$horizontal.addClass('hide');
$document.off('touchstart', touchstart);
$document.off('touchend', touchend);
}else{
//橫屏模式
$horizontal.removeClass('hide');
$document.on('touchstart', touchstart);
$document.on('touchend', touchend);
}
}
function orientationChange(){
switch(window.orientation) {
//豎屏模式
case 0:
case 180:
listener('add');
break;
//橫屏模式
case -90:
case 90:
listener('remove');
break;
}
}

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

$document.ready(function(){
//以橫屏模式進入界面,提示只支持豎屏
if(window.orientation == 90 || window.orientation == -90){
listener('remove');
}
});
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 雅江县| 平乡县| 台山市| 霍山县| 鹿邑县| 汽车| 金湖县| 永宁县| 嘉善县| 长宁县| 长白| 方城县| 湖州市| 裕民县| 金塔县| 比如县| 长沙市| 集安市| 嵩明县| 建阳市| 亚东县| 东山县| 江口县| 饶阳县| 仪征市| 岐山县| 安国市| 安徽省| 遂宁市| 安康市| 彭阳县| 静宁县| 民勤县| 宁陵县| 潍坊市| 米脂县| 龙胜| 河北省| 江源县| 怀来县| 牙克石市|