如果屏幕宽度小于960像素,请执行某些操作 [英] Do something if screen width is less than 960 px

查看:105
本文介绍了如果屏幕宽度小于960像素,请执行某些操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的屏幕宽度小于960像素,如何使jQuery做某事?不管我的窗口大小如何,下面的代码始终会触发第二个警报:

How can I make jQuery do something if my screen width is less than 960 pixels? The code below always fires the 2nd alert, regardless of my window size:

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

    alert('More than 960');
}

推荐答案

使用jQuery获取窗口的宽度.

Use jQuery to get the width of the window.

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

这篇关于如果屏幕宽度小于960像素,请执行某些操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆