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

$(window).width() returns different width than indicated by Chrome DevTools

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

你试过简化吗:

window.innerWidth

或为了向后兼容旧版浏览器

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