A JavaScript plugin that, after scrolling, snaps to blocks of content which I like to call panels. It's API makes the plugin easy to tailor to the needs of your project.

Each of the following panels will explain a specific aspect of the PanelSnap plugin.

Basic setup

<!doctype html>
    <script src="/path/to/panelsnap.js" defer></script>
        document.addEventListener("DOMContentLoaded", function() {
          new PanelSnap();


  var defaultOptions = {
    container: document.body,
    panelSelector: '> section',
    directionThreshold: 50,
    delay: 0,
    duration: 300,
    easing: function(t) { return t },

  new PanelSnap(options);

Options explained

(element) The (scrolling) container that contains the panels.
(string) The css selector to find the panels. (scoped within the container).
(interger) The amount of pixels required to scroll before the plugin detects a direction and snaps to the next panel.
(integer) The amount of miliseconds the plugin pauzes before snapping to a panel.
(integer) The amount of miliseconds in which the plugin snaps to the desired panel.
(function) An easing function specificing the snapping motion.


on([string] eventName, [function] callbackFunction(panel))
Subscribe to a specific event with your own function. Where eventName is one of `activatePanel`, `snapStart`, `snapStop` and callbackFunction is a function that gets called with the panel that is the subject of the event.
off([string] eventName, [function] callbackFunction(panel))
Unsubscribe one of your subscriptions. Where eventName is one of `activatePanel`, `snapStart`, `snapStop` and callbackFunction is the function that was used to subscribe to the event.
snapToPanel([DOM Element] panel)
Trigger a snap to a panel. Where panel is one of the panels within the container.
Destroy the panelsnap instance and clear all state & eventlisteners. This allows for a new PanelSnap instance to be created on the same container if so desired.


Common usecases are explained through a set of demos.

These demos can also be found on GitHub.