如何仅显示嵌入式JavaScript桌面设备(宽度> 1024像素)

问题描述 投票:0回答:1

如何仅渲染嵌入式JavaScript桌面设备(宽度> 1024像素)

我必须搜索许多代码,但是不起作用

谢谢

javascript pagespeed pagespeed-insights
1个回答
0
投票

我不太确定您是什么意思是呈现嵌入式JavaScript,但我假设您的意思是只想在宽度超过1024像素的设备上运行代码。

也许类似以下内容的工作:

if (window.innerWidth >= 1024) {
  // Code to run on wide displays only
  console.log("This will only happen if the window is wide enough");
}

https://developer.mozilla.org/en-US/docs/Web/API/window/innerWidth

© www.soinside.com 2019 - 2024. All rights reserved.