Snap.js is a JavaScript library for building draggable side navigation panels on touch devices. It enables slide-in menus from the left or right screen edge, driven by a gesture-based state machine that interprets drag and flick gestures to open and close the panel.
The library distinguishes horizontal menu drags from vertical scrolling by analyzing the initial touch movement angle, and locks menu movement to a single axis to prevent interference. It uses hardware-accelerated CSS transforms for smooth animations and provides configurable snap thresholds that determine whether a drag should open or close the menu based on release distance. Event listeners are attached to the document body, with support for excluding specific child elements from triggering the menu.
Snap.js exposes a programmatic toggle API for opening or closing menus without gesture input, along with lifecycle callbacks that fire at drag start, open, close, and animation completion. It also supports custom CSS class application, drag direction restriction, and real-time querying of the menu's position and open percentage.