2016-03-06 58 views
0

我有以下兩個媒體查詢如何模擬orientationchange獲取css數據?

@media screen and (orientation : portrait) { 
    .rect {width:100px;} 
} 

@media screen and (orientation : landscape) { 
    .rect {width:200px;} 
} 

當我啓動index.php我需要兩個變量即刻例如

var rect_portrait = width // when orientation is portrait (100 px) 
var rect_landscape = width // when orientation is landscape (200 px) 

如何實現?預先感謝您

+0

landscape_width = portrait_height; landscape_height = portrait_width; – Andrew

+0

安德魯原諒我的低jQuery技能,但我怎樣才能使用您提供的解決方案? –

回答

1

在這裏,你去!

landscape_height = $(window).innerHeight(); 
landscape_width = $(window).innerWidth(); 

現在可以決定肖像VS肖像如下:

if(landscape_height < landscape_width){ 
    console.log('landscape'); 
    //do something 
}else if(landscape_height > landscape_width){ 
    console.log('portrait'); 
    //do somethihng 
} 

我們模擬扭轉的檢測風景VS肖像的條件邏輯

+0

非常感謝Anubhab! –