js判斷橫豎屏及禁止瀏覽器滑動條示例
更新時間:2014年04月29日 17:13:48 作者:
這篇文章主要介紹了使用js如何判斷橫豎屏及禁止瀏覽器滑動條,需要的朋友可以參考下
復制代碼 代碼如下:
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');
}
});
相關(guān)文章
chrome瀏覽器不支持onmouseleave事件的解決技巧
發(fā)現(xiàn)給div加的 onmouseleave事件在chrome 中不起效果,下面與大家分享下具體的解決方法,不會的朋友可以了解下哈,希望對大家有所幫助2013-05-05父元素與子iframe相互獲取變量和元素對象的具體實現(xiàn)
父元素與子iframe相互獲取變量和元素對象的方法有很多,本文提供了一些不錯的示例另收集網(wǎng)上的一些,可以參考下2013-10-10