亲测方法:
(1)隐藏浏览器滚动条
// JS原生方法
document.body.parentNode.style.overflowY = "hidden";
// jquery方法
$("body").parent().css("overflow-y","hidden");
(2)显示浏览器滚动条
// JS原生方法
document.body.parentNode.style.overflowY = "auto";
// jquery方法
$("body").parent().css("overflow-y","auto");
网络其他方法:
PS:测试有瑕疵,要用请慎重!!
(1)禁止滚动,滚动条不消失,页面大小不闪动
//禁止滚动条滚动
function unScroll() {
var top = $(document).scrollTop();
$(document).on('scroll.unable',function (e) {
$(document).scrollTop(top);
})
}
//移除禁止滚动条滚动
function removeUnScroll() {
$(document).unbind("scroll.unable");
}
(2)禁止滚动,滚动条消失,会有闪动
//滚动条消失
$('html,body').css({'overflow': 'hidden'});
//滚动条出现
$('html,body').css({'overflow': 'auto'});
标签:
JavaScript