Convert Figma logo to code with AI

imakewebthings logowaypoints

Waypoints is a library that makes it easy to execute a function whenever you scroll to an element.

10,382
1,338
10,382
102

Top Related Projects

Increase your landing page conversion rates.

26,486

Animate on scroll library

10,405

Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll.

9,901

Reveal CSS animation as you scroll down a page

Animate elements as they scroll into view.

Quick Overview

Waypoints is a JavaScript library that makes it easy to trigger a function when you scroll to an element. It's commonly used for things like triggering animations or events when the user scrolls to a certain point on the page.

Pros

  • Lightweight and Efficient: Waypoints is a small, fast library that doesn't add a lot of overhead to your website.
  • Highly Customizable: The library provides a lot of options and callbacks to fine-tune how it behaves.
  • Cross-Browser Compatibility: Waypoints works across a wide range of modern browsers.
  • Actively Maintained: The project is regularly updated and maintained by the developers.

Cons

  • Dependency on jQuery: Waypoints requires the jQuery library to be included, which may not be desirable for all projects.
  • Limited Functionality: While Waypoints is great for basic scroll-based triggers, it may not have all the features needed for more complex scrolling interactions.
  • Potential Performance Issues: If not used carefully, Waypoints can potentially cause performance issues on pages with a large number of elements.
  • Lack of TypeScript Support: The library does not provide official TypeScript definitions, which may be a drawback for some developers.

Code Examples

Here are a few examples of how to use Waypoints:

  1. Basic Waypoint:
var waypoint = new Waypoint({
  element: document.getElementById('my-element'),
  handler: function(direction) {
    console.log('Scrolled to ' + this.element.id + ' in direction ' + direction);
  }
});

This code creates a new Waypoint that triggers a function when the user scrolls to the element with the ID my-element.

  1. Offset Waypoint:
var waypoint = new Waypoint({
  element: document.getElementById('my-element'),
  handler: function(direction) {
    console.log('Scrolled to ' + this.element.id + ' in direction ' + direction);
  },
  offset: '50%'
});

This example sets the waypoint to trigger when the element is 50% visible on the screen.

  1. Horizontal Waypoint:
var waypoint = new Waypoint({
  element: document.getElementById('my-element'),
  handler: function(direction) {
    console.log('Scrolled to ' + this.element.id + ' in direction ' + direction);
  },
  horizontal: true
});

This code creates a horizontal waypoint that triggers when the user scrolls horizontally to the element.

  1. Group Waypoints:
var waypoints = Waypoint.groupBy(document.querySelectorAll('.my-elements'));
waypoints.forEach(function(group) {
  group.forEach(function(waypoint) {
    waypoint.destroy();
  });
});

This example groups multiple waypoints together and then destroys them all at once.

Getting Started

To get started with Waypoints, follow these steps:

  1. Include the Waypoints library in your HTML file:
<script src="https://cdnjs.cloudflare.com/ajax/libs/waypoints/4.0.1/jquery.waypoints.min.js"></script>
  1. Create a new Waypoint instance and pass in the necessary options:
var waypoint = new Waypoint({
  element: document.getElementById('my-element'),
  handler: function(direction) {
    // Do something when the waypoint is triggered
    console.log('Scrolled to ' + this.element.id + ' in direction ' + direction);
  }
});
  1. Customize the Waypoint options to fit your needs, such as the offset, horizontal scrolling, and more.

  2. If you need to remove or destroy a Waypoint, you can call the destroy() method on the Waypoint instance.

That's the basic setup for using Waypoints in your project. Refer to the project's documentation for more advanced usage and examples.

Competitor Comparisons

Increase your landing page conversion rates.

Pros of Ouibounce

  • Focused on exit-intent popups, making it specialized for this specific use case
  • Lightweight and easy to implement with minimal configuration
  • Includes built-in cookie support for controlling popup frequency

Cons of Ouibounce

  • Limited in functionality compared to Waypoints' versatile scroll-based triggers
  • Less actively maintained, with fewer recent updates and contributions
  • Lacks the extensive documentation and examples provided by Waypoints

Code Comparison

Ouibounce implementation:

ouibounce(document.getElementById('ouibounce-modal'), {
  aggressive: true,
  timer: 0,
  callback: function() { console.log('Ouibounce fired!'); }
});

Waypoints implementation:

var waypoint = new Waypoint({
  element: document.getElementById('waypoint-element'),
  handler: function(direction) {
    console.log('Waypoint triggered!', direction);
  }
});

Both libraries offer simple implementations, but Waypoints provides more flexibility in terms of trigger points and directional awareness. Ouibounce is more specialized for exit-intent popups, while Waypoints offers a broader range of scroll-based interactions.

26,486

Animate on scroll library

Pros of AOS

  • Simpler API and easier to implement for basic scroll animations
  • Includes a wider variety of pre-built animation effects
  • Smaller file size, leading to faster load times

Cons of AOS

  • Less flexible for complex scroll-based interactions
  • Limited customization options compared to Waypoints
  • May not perform as well with a large number of animated elements

Code Comparison

Waypoints:

var waypoint = new Waypoint({
  element: document.getElementById('element'),
  handler: function(direction) {
    console.log('Scrolled to waypoint!')
  }
})

AOS:

<div data-aos="fade-up" data-aos-duration="1000">
  This element will fade up as you scroll
</div>

Waypoints offers more programmatic control, while AOS provides a simpler, declarative approach for basic animations. Waypoints is better suited for complex scroll-based interactions, whereas AOS excels in quickly implementing common scroll animations with minimal code.

Both libraries have their strengths, and the choice between them depends on the specific requirements of your project. Consider factors such as the complexity of desired animations, performance needs, and ease of implementation when making your decision.

10,405

Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll.

Pros of lax.js

  • Lightweight and easy to implement
  • Offers a wide range of pre-built animations and effects
  • Supports mobile devices and responsive design out of the box

Cons of lax.js

  • Less flexible for complex scroll-based interactions
  • Limited documentation and community support
  • May require additional JavaScript for more advanced functionality

Code Comparison

lax.js:

lax.init()

lax.addDriver('scrollY', function () {
  return window.scrollY
})

lax.addElements('.selector', {
  scrollY: {
    translateY: [
      ["elInY", "elOutY"],
      [0, 'screenHeight']
    ]
  }
})

Waypoints:

var waypoint = new Waypoint({
  element: document.getElementById('element'),
  handler: function(direction) {
    console.log('Scrolled to waypoint!')
  }
})

Summary

lax.js is a lightweight library focused on creating smooth scroll-based animations with minimal setup. It offers pre-built effects and good mobile support. However, it may be less suitable for complex interactions and has limited documentation.

Waypoints provides more flexibility for scroll-based events and has better documentation, but it requires more setup and may be overkill for simple animations. The choice between the two depends on the specific project requirements and complexity of desired scroll interactions.

9,901

Reveal CSS animation as you scroll down a page

Pros of WOW

  • Lightweight and simple to use, focusing solely on scroll animations
  • Offers a wide range of pre-defined animation effects out of the box
  • Easy to customize animations without extensive JavaScript knowledge

Cons of WOW

  • Limited to scroll-based animations, less versatile than Waypoints
  • Lacks advanced features like sticky elements or horizontal scrolling
  • May require additional libraries for more complex scroll-based interactions

Code Comparison

WOW:

new WOW().init();

<div class="wow fadeInUp" data-wow-duration="1s" data-wow-delay="0.5s">
  Animated content
</div>

Waypoints:

var waypoint = new Waypoint({
  element: document.getElementById('element'),
  handler: function(direction) {
    console.log('Scrolled to waypoint!')
  }
})

WOW is more declarative and HTML-driven, while Waypoints offers more programmatic control and flexibility. WOW is ideal for quick, simple scroll animations, whereas Waypoints is better suited for complex scroll-based interactions and custom functionality.

Both libraries serve different purposes and cater to different use cases. WOW excels in simplicity and ease of use for basic scroll animations, while Waypoints provides a more robust framework for advanced scroll-based interactions and custom implementations.

Animate elements as they scroll into view.

Pros of ScrollReveal

  • More focused on animation effects, offering a wider range of scroll-triggered animations
  • Easier to implement for simple scroll-based reveal animations
  • Smaller file size, leading to potentially faster load times

Cons of ScrollReveal

  • Less flexible for complex scroll-based interactions
  • Limited to reveal animations, while Waypoints can trigger any custom JavaScript
  • May require more manual setup for advanced use cases

Code Comparison

ScrollReveal:

ScrollReveal().reveal('.element', {
    delay: 200,
    distance: '50px',
    origin: 'bottom'
});

Waypoints:

var waypoint = new Waypoint({
    element: document.querySelector('.element'),
    handler: function() {
        // Custom JavaScript here
    }
});

ScrollReveal is more declarative and focused on reveal animations, while Waypoints offers a more general-purpose approach for scroll-based interactions. ScrollReveal's API is simpler for basic reveal effects, but Waypoints provides more flexibility for custom behaviors. Both libraries have their strengths, and the choice depends on the specific requirements of your project.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Waypoints

Waypoints is a library that makes it easy to execute a function whenever you scroll to an element. Build Status

var waypoint = new Waypoint({
  element: document.getElementById('thing'),
  handler: function(direction) {
    alert('You have scrolled to a thing')
  }
})

If you're new to Waypoints, check out the Getting Started guide.

Read the full documentation for more details on usage and customization.

Shortcuts

In addition to the normal Waypoints script, extensions exist to make common UI patterns just a little easier to implement:

Contributing

If you want to report a Waypoints bug or contribute code to the library, please read the Contributing Guidelines. If you need help using Waypoints, please do not open an issue. Instead, ask the question on Stack Overflow and tag it with #jquery-waypoints. Be sure to follow the guidelines for asking a good question.

License

Copyright (c) 2011-2014 Caleb Troughton. Licensed under the MIT license.

NPM DownloadsLast 30 Days