[英]Combine scroll and resize events after document is ready
In this example all things work nice, but when scrolling in large window width then resize it to small window the div still take the .fixed class 在这个例子中,所有东西都很好用,但是当在大窗口宽度中滚动然后将其调整到小窗口时,div仍然会使用.fixed类
So it's working just when the scroll is 0px(top), but not when resizing the window to a small size while scroll it more than 0px 因此,当滚动为0px(顶部)时它正在工作,但是当将窗口调整为小尺寸而滚动它超过0px时则不行
I want it to remove the .fixed class when detecting scroll 0 and window is less than 600px even if the document is already loaded 我希望它在检测到滚动0时删除.fixed类,并且即使文档已经加载,窗口也小于600px
Example: http://jsbin.com/arehow/1/edit 示例: http : //jsbin.com/arehow/1/edit
Your condition is wrong. 你的病情有误。
if ( $(window).width() > 600 ) {
$('div').addClass('fixed');
}
} else {
if ( $(window).width() > 600 ) {
$('div').removeClass('fixed');
}
}
Both conditions are >600 ... make the last condition as < 600 两个条件都> 600 ......使最后一个条件为<600
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.