Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to detect direction #283

Open
ukropf opened this issue Nov 1, 2015 · 2 comments
Open

How to detect direction #283

ukropf opened this issue Nov 1, 2015 · 2 comments

Comments

@ukropf
Copy link

ukropf commented Nov 1, 2015

How i can to detect scroll direction (up or down) in beforeMove callback function?

@hobz
Copy link

hobz commented Dec 10, 2015

I did it this way, not sure the best way, but it worked for me
In the onepagescroll setup script:

var prevIndex = 1;
jQuery(".main").onepage_scroll({
...
afterMove: function(index) {
...
prevIndex = parseInt(jQuery('body').attr('class').substr(jQuery('body').attr('class').indexOf('viewing-page-')+13)); //at the very end of afterMove method
},

Then I check whether prevIndex is less or more than index variable where I need it and it works for me.

@projektlounge
Copy link

projektlounge commented May 3, 2017

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

    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants