What happened to triggerOnce in Waypoints 3.0?

I recently updated jquery-waypoints from 2.x to 3.x in my project and found that a lot of my code broke. All references to $(this) inside my handlers should have been changed to $(this.element) , which, as I understood it, was the cause of my problems, was easy enough to fix.

I was not able to figure out what happened with the triggerOnce option, which will prevent the waypoint from triggering multiple times. Any idea why this was removed and how can I achieve the same functionality?

+5
source share
3 answers

I understood the solution. Adding this.disable () to the end of my handler disables the waypoint after it is fired, preventing it from snagging. I really think this should be documented.

+2
source

I know that the answer has already been marked as correct, but I would like to go beyond the scope of a simple comment.

3.0, being the main version, interrupted the changes. One of them was the removal of triggerOnce . This is noted in changelog . This is also mentioned in destroy docs , where using destroy at the end of the handler is called as an alternative to the old triggerOnce .

triggerOnce n’t the same as calling destroy because all Waypoint methods were called in jQuery objects. Elements in these jQuery objects may have multiple waypoints attached to them, but there was no way to separate them after they were created. If you called destroy , all waypoints on this element were destroyed. The triggerOnce option, however, worked on a separate waypoint backstage. Now that 3.0 returns instances of the Waypoint class directly, and this in the handler is a reference to the Waypoint instance instead of the element, there is no difference between triggerOnce and calling this.destroy() to complete the handler. Thus, the code has been deleted.

+6
source

If you need to disable jQuery waypoint (v3.0):

 $('.my-waypoint').waypoint(function(direction){ // Do some stuff this.destroy(); }); 
0
source

Source: https://habr.com/ru/post/1209808/


All Articles