explaingit

jakiestfu/snap.js

5,957JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

JavaScript library for adding a swipe-to-open side drawer navigation panel to mobile web pages, handling touch gestures, flick detection, and CSS3 slide animations with no other dependencies required.

Mindmap

mindmap
  root((snap.js))
    What it does
      Side drawer navigation
      Touch gesture handling
      CSS3 slide animations
    Features
      Left and right drawers
      Swipe and flick support
      Drag handle element
      JavaScript API
    Browser support
      Android 2.3+
      IE 7 and later
    Use cases
      Mobile side menu
      App-style navigation
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add a swipe-open side menu to a mobile web app that behaves like a native app navigation drawer.

USE CASE 2

Create a left or right sliding panel navigation for a mobile website without any other JavaScript library.

USE CASE 3

Control a side drawer programmatically from buttons and listen to open/close events to trigger other animations.

USE CASE 4

Restrict drawer opening to a specific drag handle zone on the screen edge.

Tech stack

JavaScriptCSS3

Getting it running

Difficulty · easy Time to first run · 5min

No external dependencies, include the script file and call new Snap on your main content element to get started.

In plain English

Snap.js is a JavaScript library for creating side-drawer navigation on mobile web pages. This pattern, sometimes called a shelf or side menu, is the kind that slides the main content sideways to reveal a hidden panel on the left or right. It was popularized by mobile apps like Facebook and Path. The library works without any other JavaScript framework, so it can be dropped into any project. It handles all touch interaction on mobile devices, including detecting swipe gestures, responding to flick motions, and figuring out whether the user intends to scroll the page vertically or slide the drawer open sideways. Opening and closing animations run through CSS3 transitions for smooth performance, with fallbacks for older Internet Explorer versions. To set it up, a developer creates a new Snap instance and points it at the main content element on the page. A range of settings controls how far the pane slides, how fast the animation runs, whether tapping an open pane closes it, and whether touch dragging is enabled at all. Both left and right drawers are supported, and either side can be disabled independently. A drag handle element can also be designated so only a specific area of the screen initiates the slide. Snap.js exposes a JavaScript API for controlling the drawer from code: opening to a specific side, closing, or expanding fully. It fires events at each stage of interaction, such as when dragging starts, during movement, and when animation finishes. These event hooks allow responding to the menu's state changes from other parts of the page. The library supports a wide range of browsers, including Firefox, WebKit-based browsers on older Android devices (2.3.x), and Internet Explorer from version 7 onward, with full transition support starting at version 10.

Copy-paste prompts

Prompt 1
Show me the minimal HTML structure and JavaScript setup to create a left-side drawer in Snap.js that opens when the user swipes from the left edge of the screen.
Prompt 2
I want a hamburger button that opens a Snap.js drawer on click and closes it when the user taps outside the panel. Show me the setup and event listener code.
Prompt 3
How do I configure Snap.js to only allow the drawer to open from a designated drag handle element, and disable dragging on the rest of the page?
Prompt 4
Show me how to use Snap.js events to detect when the drawer finishes opening and then fade in the menu items using a CSS transition.
Open on GitHub → Explain another repo

← jakiestfu on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.