[英]How can I detect if a browser is mobile and switch between normal and mobile?
I assume it involves the view-port somehow, but I'm not good at mobile.我认为它以某种方式涉及视口,但我不擅长移动。 I'd like to re-size my font and move my elements around.我想重新调整字体大小并移动我的元素。
I see that HTML 5 Boilerplate comes in a mobile form, how and when would I switch to that?我看到 HTML 5 Boilerplate 以移动形式出现,我将如何以及何时切换到该形式?
It depends on what you need to change.这取决于你需要改变什么。
To change Boilerplate to Boilerplate Mobile you could have a server-side condition and render a completely different page.要将 Boilerplate 更改为 Boilerplate Mobile,您可以使用服务器端条件并呈现完全不同的页面。 If you are using some kind of dynamic framework or have direct access to the server you can check for User-Agent如果您使用某种动态框架或可以直接访问服务器,您可以检查 User-Agent
Here is an article that explains how to use mobile-specific JS, CSS and HTML. 这是一篇解释如何使用特定于移动设备的 JS、CSS 和 HTML 的文章。 Hope it helps.希望能帮助到你。
You may parse the user agent to determine the mobile platform (eg, iPhone, iPad, iPod, Android, Opera, Android, BlackBerry, hpwOS, Windows PhoneOS, etc.).您可以解析用户代理以确定移动平台(例如,iPhone、iPad、iPod、Android、Opera、Android、黑莓、hpwOS、Windows PhoneOS 等)。
And it is better to use a @media query in CSS to take advantage of the screen dimensions.最好在 CSS 中使用 @media 查询来利用屏幕尺寸。
For reference:以供参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.