根据屏幕分辨率运行 jquery 代码的正确方法

发布于 2025-01-01 09:34:56 字数 138 浏览 3 评论 0原文

我的网站上有一个多级巨型菜单(使用 jquery 插件),但是,当在移动设备上查看该网站时,我想在菜单上运行不同的 JS 代码,以便有一个适合移动设备的选择菜单。我检查要运行哪些代码的正确方法是什么,例如屏幕宽度是否小于 768px?有处理这个问题的标准方法吗?

I have a multi-level mega menu on my site (using jquery plugin), however, when the site is being viewed on a mobile device, I want to run different JS code on the menu, in order to have a mobile friendly select menu. What is the correct way for me to check which code to run, something like if screen width less than 768px wide? Is there a standard way of dealing with this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魂牵梦绕锁你心扉 2025-01-08 09:34:56

检查 window.screen 对象。

if( screen.width < 768 ) {
    // do some js
}

check the window.screen object.

if( screen.width < 768 ) {
    // do some js
}
你怎么敢 2025-01-08 09:34:56

您好,根据问题,您可以使用 link 标记中的媒体属性来更改样式和代码

有关详细说明,请参阅此处的博客。

创建-mobile-version-of-your-website

Hi as per the Question you can change the styles and code by using media attribute in your link tag

For detailed explaination refer the blog here..

Create-a-mobile-version-of-your-website

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文