admin管理员组文章数量:1303530
I want some jQuery functions for a dropdown menu to run only if the the screen size is under 768px and a different dropdown menu function to run if it is above that value. How would I do this in JavaScript?
I want some jQuery functions for a dropdown menu to run only if the the screen size is under 768px and a different dropdown menu function to run if it is above that value. How would I do this in JavaScript?
Share Improve this question asked Nov 3, 2011 at 14:46 firefusionfirefusion 1,1072 gold badges14 silver badges26 bronze badges 2- 2 possible duplicate of How to detect the screen resolution with JavaScript? – Quentin Commented Nov 3, 2011 at 14:47
- Window size is far more important than a screen resolution. – Quentin Commented Nov 3, 2011 at 14:47
2 Answers
Reset to default 8You can get the size of the window (screen size is mostly irrelevant, you care about the actual space you have for rendering) using the .height()
and .width()
methods:
if( $(window).width() > 768 ) {
// Large menu
} else {
// Small menu
}
In your ready function, you could test screen height and width like this :
if (screen.width<=768)
{
//Do this
}
else
本文标签: jqueryRunning different JavaScript at different screen resolutionsStack Overflow
版权声明:本文标题:jquery - Running different JavaScript at different screen resolutions - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741758760a2396273.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论