$(window).width() 返回的宽度与 Chrome DevTools 指示的宽度不同

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

$(window).width() == 768
时,执行
alert()
。但在
Chrome DevTools
中,当宽度为 786px 时,实际上会发生这种情况。为什么以及如何让我的 JS 在 768px 而不是 786 处触发?

jquery width
2个回答
1
投票

你有没有简单地尝试过:

window.innerWidth

或向后兼容旧版浏览器

window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth

0
投票

Estou tendo o mesmo Problema,trabalhando em um projeto que usa JQuery 2.1.3.

Tentei todas opções que consegui para obter o Width correto。 Por fim,busquei qual a medida que o Jquery imprimia que period equale que eu queria no navegador do usuário, e assim funcionou.

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