peachananr / onepage-scroll

Create an Apple-like one page scroller website (iPhone 5S website) with One Page Scroll plugin
http://peachananr.github.io/onepage-scroll/Demo/demo.html
9.54k stars 2.06k forks source link

Detecting scroll direction? #313

Open henrikrosendalvonessen opened 7 years ago

henrikrosendalvonessen commented 7 years ago

I need to know the scroll direction, and be able to use this information in the "beforeMove" function, because I'm animating an element based on the scroll direction. Placing my animation in the "afterMove" function, creates way too big of a delay, while waiting for the scroll transition to end.

Anyone figured out how to accomplish this yet?

projektlounge commented 7 years ago

Easiest would be like this:

    $(document).ready(function(){

      var prevIndex = 1;

      $(".main").onepage_scroll({
        sectionContainer: "section",
        responsiveFallback: 600,
        loop: true,
        afterMove: function(index) {
          if (prevIndex<index) {
            // move next page
            console.debug("next > afterMove("+index+") prvIdx:"+prevIndex);
          } else {
            // move prev page
            console.debug("prev > afterMove("+index+") prvIdx:"+prevIndex);
          }
          prevIndex = index; //at the very end of afterMove method
        }
      });

    });