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)文章
在B/S開發(fā)中經(jīng)常用到的JavaScript技術(shù)
javascript運用中,經(jīng)常用到的代碼,建議每段代碼都要看下,注意本文有三頁,仔細(xì)看玩,逐個研究透徹,那么網(wǎng)頁中常見的問題,你也就熟悉掌握了2008-05-05
js parentElement和offsetParent之間的區(qū)別
這里主要說的是 offsetParent 屬性,這個屬性在 MSDN 的文檔中也沒有解釋清楚,這就讓人更難理解這個屬性。 這幾天在網(wǎng)上找了些資料看看,再加上自己的一些測試,對此屬性有了那么一點的了解,在這里總結(jié)一下。2010-03-03
JavaScript實現(xiàn)定時任務(wù)隊列的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何使用JavaScript實現(xiàn)一個基于一定時間間隔連續(xù)執(zhí)行任務(wù)隊列的功能,文中的示例代碼講解詳細(xì),需要的小伙伴可以參考下2023-11-11

