js判斷橫豎屏及禁止瀏覽器滑動條示例
更新時間:2014年04月29日 17:13:48 作者:
這篇文章主要介紹了使用js如何判斷橫豎屏及禁止瀏覽器滑動條,需要的朋友可以參考下
復(fù)制代碼 代碼如下:
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(){
//以橫屏模式進(jìn)入界面,提示只支持豎屏
if(window.orientation == 90 || window.orientation == -90){
listener('remove');
}
});
相關(guān)文章
同時使用n個window onload加載實(shí)例介紹
window onload加載多個同時使用,想必有很多人沒有用過吧,接下來為大家詳細(xì)介紹下具體的使用方法,感興趣的朋友可以參考下2013-04-04chrome瀏覽器不支持onmouseleave事件的解決技巧
發(fā)現(xiàn)給div加的 onmouseleave事件在chrome 中不起效果,下面與大家分享下具體的解決方法,不會的朋友可以了解下哈,希望對大家有所幫助2013-05-05父元素與子iframe相互獲取變量和元素對象的具體實(shí)現(xiàn)
父元素與子iframe相互獲取變量和元素對象的方法有很多,本文提供了一些不錯的示例另收集網(wǎng)上的一些,可以參考下2013-10-10實(shí)現(xiàn)點(diǎn)擊列表彈出列表索引的兩種方式
使用利用事件冒泡委托給列表的父節(jié)點(diǎn)去處理的方式第二種方式就是使用閉包了,感興趣的你可以參考下本文,或許對你學(xué)習(xí)js有所幫助2013-03-03