gpt4 book ai didi

javascript - 如果屏幕宽度小于 960 像素,请执行某些操作

转载 作者:IT老高 更新时间:2023-10-28 13:14:25 26 4
gpt4 key购买 nike

如果我的屏幕宽度小于 960 像素,我如何让 jQuery 执行某些操作?无论我的窗口大小如何,下面的代码都会触发第二个警报:

if (screen.width < 960) {
alert('Less than 960');
}
else {

alert('More than 960');
}

最佳答案

使用 jQuery 获取窗口的宽度。

if ($(window).width() < 960) {
alert('Less than 960');
}
else {
alert('More than 960');
}

关于javascript - 如果屏幕宽度小于 960 像素,请执行某些操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7715124/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com