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

如果我的屏幕宽度小于960像素,我如何让jQuery做一些事情?无论窗口大小如何,下面的代码始终会触发第二个警报:


if (screen.width < 960) {

    alert('Less than 960');

}

else {


    alert('More than 960');

}


12345678_0001
浏览 592回答 3
3回答

catspeake

使用jQuery获取窗口的宽度。if ($(window).width() < 960) {&nbsp; &nbsp;alert('Less than 960');}else {&nbsp; &nbsp;alert('More than 960');}
打开App,查看更多内容
随时随地看视频慕课网APP