admin管理员组文章数量:1278720
I want to conditionally alter what the user sees on the photo gallery web site I'm going to create based on if the device being used to view the site is in portrait/vertical vs. landscape/horizontal mode/orientation. Is this possible?
I want to conditionally alter what the user sees on the photo gallery web site I'm going to create based on if the device being used to view the site is in portrait/vertical vs. landscape/horizontal mode/orientation. Is this possible?
Share Improve this question asked Apr 12, 2013 at 20:55 B. Clay Shannon-B. Crow RavenB. Clay Shannon-B. Crow Raven 10.3k157 gold badges501 silver badges896 bronze badges 2- This previous answer might help: link – mconlin Commented Apr 12, 2013 at 21:00
- All good answers; I'm not sure which one to prefer yet. Actually, I also need to know whether the device is a "phone" or not. Here's the method behind my madness: I will have two "views" - one with vertical thumbnails and full-size photos, the other with landscape thumbnails and full-size photos. If the device is a phone, I want it to toggle between those modes based on orientation. For a larger device, though (such as a laptop or desktop), I want to allow the user to explicitly choose which orientation photos they want to see. – B. Clay Shannon-B. Crow Raven Commented Apr 12, 2013 at 21:08
2 Answers
Reset to default 6Try the orientationchange
event handler, something like this:
$(window).bind("orientationchange", function(evt){
alert(evt.orientation);
});
Here's the jQuery Mobile entry on detecting and firing the orientationchange
event.
If you are just changing the layout, consider CSS Media Queries instead.
In Chrome 7 and Firefox 3.6, there is the deviceorientation
event which you can listen to.
In response to your ment, a simple way of detecting tablets and phones is to detect the screen resolution and size. Tablets generally have higher display resolutions than phones. Media Queries can determine these factors.
As for tablet-phone options
If your device is a phone, you can toggle CSS using Media Queries based on device orientation.
If the device is a tablet, you can toggle the CSS using JS using the body id/class switching or by swapping out stylesheets.
本文标签: javascriptCan I determine if a device is in portrait or landscape mode using jqueryStack Overflow
版权声明:本文标题:javascript - Can I determine if a device is in portrait or landscape mode using jquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741253784a2366281.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论