Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scroll-snap-api

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scroll-snap-api

Interact with CSS scroll-snap

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2K
decreased by-11.12%
Maintainers
1
Weekly downloads
 
Created
Source

scroll-snap-api

Interact with CSS scroll-snap.

Zero dependencies.

Automatically accounts for scroll-padding.

Install

yarn add scroll-snap-api

npm install --save scroll-snap-api

Or use directly

import * as scrollSnapApi from 'https://cdn.pika.dev/scroll-snap-api';

Usage

Scroll an element to the next snap position in a direction

import { scrollSnapToNext } from 'scroll-snap-api';

scrollSnapToNext( scrollingElement, 'right' ); // 'left', 'right', 'up', 'down'

Get the possible scroll positions

import { getScrollSnapPositions } from 'scroll-snap-api';

const scroll = getScrollSnapPositions( scrollingElement );

/*
{
  x: [ 0, 100, 150, 200 ],
  y: [ 0, 200, 400, 600, 800 ],
}
*/

Get the raw snap positions

Note: these are not scroll positions.

import { getSnapPositions } from 'scroll-snap-api';

const snap = getSnapPositions( scrollingElement );

/*
{
  x: {
    start: [ 0, 100 ],
    center: [ 300 ],
    end: [ 500 ],
  },
  y: {
    start: [ 0 ],
    center: [ 250, 500, 750 ],
    end: [ 1000 ],
  },
}
*/

Diagram showing difference between function calls

TODO

  • More documentation
  • Support dir="rtl"

FAQs

Package last updated on 05 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc