5

I'd like to hide/show NiceScroll based on the result of an if function.

In my html there are three sections which are scrolled from left to right one by one.

My script is as follows:

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

It hides when scrolling outside of section 2, but when scrolling back it doesn't reappear.

Szymon
  • 1,254
  • 19
  • 34

1 Answers1

4

I found a solution to this answer on Github.

It's better to create NiceScroll during the document ready event.

$("body").getNiceScroll().show()
Szymon
  • 1,254
  • 19
  • 34
  • Could you please provide a link and the relevant text from the answer you found on Github? –  May 06 '15 at 09:13
  • @wilbishardis thx for upvote, and here it is issue post on github https://github.com/inuyaksa/jquery.nicescroll/issues/215 – Szymon May 06 '15 at 22:53