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

scroll-behavior-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scroll-behavior-polyfill

A polyfill for the 'scroll-behavior' CSS-property

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
46K
decreased by-3.27%
Maintainers
1
Weekly downloads
 
Created
Source

scroll-behavior polyfill

NPM version License-mit

A polyfill for the new CSS property: scroll-behavior.

Installation

You can npm install it like this:

npm install scroll-behavior-polyfill

Adding the polyfill

Importing it

The polyfill will be feature detected and applied if and only if the browser doesn't support the property already. To include it, add this somewhere:

import "scroll-behavior-polyfill"

Conditionally importing it

Preferably, you should feature detect before including the code since there is no need to include a polyfill that won't ever be applied.

One way to do so is with async imports:

if (!"scrollBehavior" in document.documentElement.style) {
	await import("scroll-behavior-polyfill");
}

Usage

You can use scroll-behavior exactly how you expect to:

As a CSS-property

#something {
	scroll-behavior: smooth
}

As an inline-style

<div style="scroll-behavior: smooth"></div>

As an imperative style property

element.style.scrollBehavior = "smooth";

Dependencies

This polyfill expects requestAnimationFrame to be defined. Please polyfill it!

Caveats

  • You cannot set scrollLeft or scrollTop. There is no way to overwrite the property descriptors for those operations. Instead, use scroll(), scrollTo or scrollBy which does the exact same thing.
  • Element.scrollIntoView() is not polyfilled at the moment.
  • Elements inside ShadowRoots won't be detected at the moment. It probably will be soon.

FAQs

Package last updated on 08 Sep 2017

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