我想NiceScroll根据功能的结果隐藏/显示if。
在我的html书中,有三个部分,它们从左到右一一滚动。
我的脚本如下:
var section2 = $('#section2').offset().left;
$(window).scroll(function(){
var scrollZpos = $(document).scrollLeft();
if (scrollZpos <= section2 ) {
$("body").getNiceScroll().hide();
}
if (scrollZpos == section2 ) {
$("body").niceScroll({touchbehavior:false,cursorcolor:"#67a5df",horizrailenabled:false,cursoropacitymax:1,autohidemode:false,cursorwidth:10,cursorborder:0,cursorborderradius:0,cursorminheight:180});
}
else if(scrollZpos >= section2 ){
$("body").getNiceScroll().hide();
}
});
Run Code Online (Sandbox Code Playgroud)
滚动到第2节之外时,它会隐藏,但向后滚动时,它不会再次出现。