imakewebthings / waypoints

Waypoints is a library that makes it easy to execute a function whenever you scroll to an element.
http://imakewebthings.com/waypoints/
10.38k stars 1.33k forks source link

Having a section anchor in focus and refreshing page will make my waypoints fail #595

Open lordgammon opened 6 years ago

lordgammon commented 6 years ago

Hey! I think that my problem is not a big think, but I don't get the resolution by myself. I've got a function that will add or remove classes from Animate.css by direction of scrolling. If I'm refreshing the page (CTRL+F5) and get the focus on the section where the fade will happen, the offset is completely different and sometimes the fade classes are switched. The problem excist only on the classes "fadeInBottom" and "fadeInTop".

Here is my code:

$(fade).each(function (index, element) {
  $(fade + 'bottom').css('opacity', 0);
  $(element).waypoint({
    handler: function (direction) {
      if (direction === 'up') {
        $(element).removeClass('fadeUp');
        $(element).addClass('fadeOutDown');
      }
      else if (direction === 'down') {
        $(element).removeClass('fadeOutDown');
        $(element).addClass('fadeUp');

      }
      $(element).addClass('fadeInUp');
    }, offset: '65%'
  });
});

Thanks for the help! :)