jQuery-根据屏幕大小执行脚本 [英] jQuery - Execute scripts based on screen size

查看:150
本文介绍了jQuery-根据屏幕大小执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果屏幕/设备尺寸超过xxx像素宽,是否可以仅运行某些jQuery脚本?

Is it possible to only run certain jQuery scripts if the screen/device size is above xxx pixels wide?

例如,当人们在大于1024像素的设备上查看网站时,我只想运行幻灯片.如果有人在移动设备上访问,我只希望所有图像堆叠在一起显示...

So, for example, I only want to run a slideshow when people are viewing the site on devices bigger than 1024px. If someone visits on a mobile I just want all the images to display stacked on top of each other...

推荐答案

您可以使用$(window).width()

if($(window).width() >= 1024){
  // do your stuff
}

演示---> http://jsfiddle.net/fh2eC/1/

这篇关于jQuery-根据屏幕大小执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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