2016-03-06 55 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! –