Dea*_*ott 21 jquery responsive-design
如果屏幕/设备大小超过xxx像素宽,是否可以只运行某些jQuery脚本?
因此,例如,当人们在大于1024px的设备上查看网站时,我只想播放幻灯片.如果有人在手机上访问我只想让所有图像叠加在一起...
Moh*_*dil 64
您可以使用 $(window).width()
if($(window).width() >= 1024){
// do your stuff
}
Run Code Online (Sandbox Code Playgroud)
演示---> http://jsfiddle.net/fh2eC/1/
Sha*_*dow 22
如果要在调整窗口大小后检查宽度大小,则:
$(window).resize(function() {
if( $(this).width() > width ) {
// code
}
});
Run Code Online (Sandbox Code Playgroud)
您也可以考虑使用像https://github.com/paulirish/matchMedia.js/这样的库
if (matchMedia('only screen and (max-width: 480px)').matches) {
// smartphone/iphone... maybe run some small-screen related dom scripting?
}
Run Code Online (Sandbox Code Playgroud)