javascript - animate scroll to specific page position on scroll -


i'm trying replicate scroll event found on http://blkboxlabs.com/, when user scrolls animates screen next full height section, depending on if scroll or down.

i've got similar functionality, less smooth, , if user scrolls enough skip 2 sections, opposed stopping @ next section.

var didscroll; var lastscrolltop = 0; var delta = 5;   $(window).scroll(function(event){     didscroll = true; });  setinterval(function() {     if (didscroll) {         hasscrolled();         didscroll = false;     } }, 800);  function hasscrolled() {     var st = $(document).scrolltop();     var wintop = $(window).scrolltop();     var winbottom = wintop + ($(window).height());      // make sure scroll more delta     /*if(math.abs(lastscrolltop - st) <= delta)         return;*/      // if scrolled down , past navbar, add class .nav-up.     // necessary never see "behind" navbar.     if (st > lastscrolltop){         // scroll down         $('.fullheightscrollassist').each(function(index, element) {             var eltop = $(this).offset().top;             var elbottom = eltop + $(this).outerheight();             if(eltop > wintop && eltop < winbottom){                 $('.fullheightscrollassist').removeclass('activefullscreen');                 $(this).addclass('activefullscreen');                 $('html,body').animate({scrolltop: eltop}, 700);                 };         });     } else {         // scroll             $('.fullheightscrollassist').each(function(index, element) {                 var eltop = $(this).offset().top;                 var elbottom = eltop + $(this).outerheight();                 if(elbottom > wintop && eltop < wintop){                     $('.fullheightscrollassist').removeclass('activefullscreen');                     $(this).addclass('activefullscreen');                     $('html,body').animate({scrolltop: eltop}, 700);                     };             });     }      lastscrolltop = st; } 

you can see example @ https://jsfiddle.net/raner/vhn3oskt/2/

what i'm trying accomplish: 1. run animate scrolltop function on scroll, once. 2. kill further scrolling once animation starts, keep skipping next section.

for else might know, here's plugin found did close looking , lot smoother initial attempt.

http://www.jqueryscript.net/demo/jquery-plugin-for-smooth-scroll-snapping-panelsnap/demos/


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -