2011-02-28 168 views

回答

6

的支持內置到jQuery Mobile的。有兩個Orientation Classes這是目前根據當前的屏幕方向:

.portrait { 
    /* portrait orientation changes go here! */ 
} 
.landscape { 
    /* landscape orientation changes go here! */ 
} 

或者,如果你想有一個JavaScript事件可以綁定到orientationchange

+0

所以從上面的代碼我們必須設置肖像和風景的不同圖像大小。這是你要說的嗎?如果它的意思是我們如何設置圖像大小?因爲不同的平臺有不同的橫向屏幕尺寸。 – Lakshmanan 2011-03-01 05:38:17

+3

您是否嘗試過''? – dave1010 2011-03-01 16:48:28

5

我不認爲當手機進入橫向縱向時會觸發事件。但是,您可以編寫自定義函數來查找當前方向。在window.resize事件中寫下面的代碼。

$(window).resize(function(){ 
var height = $(window).height(); 
var width = $(window).width(); 

if(width>height) { 
    // Landscape 
    $("#img").attr("src","landscapeurl"); 
} else { 
    // Portrait 
    $("#img").attr("src","portraiturl"); 
} 
}); 

代碼從這個Here

相關問題