我有一个侧边栏,可以在桌面/iPad视图上滚动,但它也会影响移动视图。我想在移动视图/较小的屏幕上禁用此JavaScript代码。
var length = $('#filters-sidebar-wrap').height() - $('#filters-sidebar').height() + $('#filters-sidebar-wrap').offset().top;
$(window).scroll(function () {
var scroll = $(this).scrollTop();
var height = $('#filters-sidebar').height() + 'px';
if (scroll < $('#filters-sidebar-wrap').offset().top) {
$('#filters-sidebar').css({
'position': 'absolute',
'top': '40px',
'width': '290px'
});
} else if (scroll > length ) {
$('#filters-sidebar').css({
'position': 'absolute',
'bottom': '0',
'top': 'auto',
'width': '290px'
});
} else {
$('#filters-sidebar').css({
'position': 'fixed',
'top': '128px',
'width': '290px',
'height': 'height'
});
}
});
我解决了我的问题,谢谢你的帮助!
if(window.innerWidth < 992 ) {
$("#filters-sidebar").removeAttr("style");
} else {
/// Add code here