5

我想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();
    }
});

滚动到第 2 部分之外时它会隐藏,但当向后滚动时它不会重新出现。

4

1 回答 1

4

我在 Github 上找到了这个答案的解决方案。

最好在活动NiceScroll期间进行创作document ready

$("body").getNiceScroll().show()
于 2013-05-22T20:34:22.857 回答