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.34k forks source link

Disable sticky element #541

Open havardl opened 7 years ago

havardl commented 7 years ago

I'm trying to disable a sticky element in another waypoint, when scrolled passed a certain element on the page. Trying the normal enable/disable functions for waypoint elements, but that doesn't work. Are there other options for achieving this?

var sticky = new Waypoint.Sticky({
      element: $('.float-menu')[0],
      wrapper: false,
      direction: 'down up'
    });
    var waypoint = new Waypoint({
      element: document.getElementsByClassName('float-menu'),
      handler: function(direction) {
        if(direction == "up") {
          // Disable sticky
          sticky.disable();
        } else if(direction == "down") {
          //Enable sticky
          sticky.enable();
        }
      }
    });`
janwidmer commented 7 years ago

It seems like, you need to call the function like this:

this. sticky.waypoint.disable();

It diverges from the way, e.g. you have to call the destroy method..thats how I made it work..