我有如下脚本:
$(window).resize(function(){
if ($(window).width() >= 992){
var windw = this;
$.fn.followTo = function ( pos ) {
var $this = this,
$window = $(windw);
$window.scroll(function(e){
if ($window.scrollTop() > pos){
$this.css({
position: 'static',
top: pos,
marginTop: 100
});
}
else {
$this.css({
position: 'fixed',
top: 100
});
}
});
};
$('#bgForm').followTo(1550);
}
});
当浏览器的大小低于 992px 时,我想阻止位置固定。我怎样才能使用我的脚本做到这一点? 我尝试使用这段代码,但随后元素停在了位置上。 谢谢!
最佳答案
当一个简单的 CSS 媒体查询就足够了时,我不明白你为什么要使用 Javascript。除非您还没有说明您的问题?
@media only screen and (max-width: 992px) {
// Rules placed here will only apply when the
// browser window is smaller than 992px
}
关于jquery - block 位置固定在浏览器的准确宽度以下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46810923/