内容简介:我正在寻找一个脚本,当用户调整窗口大小或窗口宽度小于900px时,它会进行somenthing.翻译自:https://stackoverflow.com/questions/10642424/js-or-jquery-or-window-resize-or-when-window-width-is-less-than-npx
我正在寻找一个脚本,当用户调整窗口大小或窗口宽度小于900px时,它会进行somenthing.
嗯,你可以使用jQuery,但……
您可以订阅窗口调整大小事件,如下所示:
$(window).on("resize", function(event){
console.log( $(this).width() );
});
请注意这一点,因为当宽度小于n时执行代码的if语句在调整满足这些条件的窗口时会执行该代码的次数非常多.最好设置一些标志或向文档添加类,并使这些部分成为您的条件.
CSS媒体查询就在哪里!
但是,你问的问题听起来最适合用 CSS Media Queries 来解决.例如,如果我们想在窗口小于900px时改变主体背景颜色:
@media screen and (max-width: 900px) {
body {
background: #ccc;
}
}
对于旧版IE: https://github.com/scottjehl/Respond ,甚至还有一个很好的polyfill
翻译自:https://stackoverflow.com/questions/10642424/js-or-jquery-or-window-resize-or-when-window-width-is-less-than-npx
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Algorithms for Image Processing and Computer Vision
Parker, J. R. / 2010-12 / 687.00元
A cookbook of algorithms for common image processing applications Thanks to advances in computer hardware and software, algorithms have been developed that support sophisticated image processing with......一起来看看 《Algorithms for Image Processing and Computer Vision》 这本书的介绍吧!