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

scroll-freezer

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scroll-freezer

Frost scroll event on window. A no-jumping javascript alternative to overflow:hidden.

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ScrollFreezer

Frost scroll event on window. A no-jumping javascript alternative to overflow:hidden.

Why

What's the probelem with overflow:hidden? Well if people have their browsers defaulting to show scrollbars (not overlayed fancy ghost ones like mac/safari) content will jump to right when overflow is applied. It's kind of ugly/janky.

Public Methods

// assuming an instance
const myScrollFreezer = new ScrollFreezer('body');
MethodDescription
myScrollFreezer.freeze()      Locks scroll. Sets isFrozen=true
myScrollFreezer.defrost()      Unlocks scroll. Sets isFrozen=false
myScrollFreezer.toggleFreeze()toggle state between frozeen and defrosted
myScrollFreezer.getState()    returns an state Object. {isFrozen: bool, curScrollLockPos: number}

Usage

// Instanciate
var bodyScrollFreezer = new ScrollFreezer('body');

// starts at false
document.querySelector('.someTrigger').addEventListener('click', function(){
  bodyScrollFreezer.toggleFreeze();
}, false);

/*
 * Manual verfication Example
 */
var isFrozen = bodyScrollFreezer.getState().isFrozen;

if (isFrozen){
  bodyScrollFreezer.defrost()
} else {
  bodyScrollFreezer.freeze()
}

Credits

Technique originally seen at facebook, at least that's what @fhilM said.

Based on philm SO answer 🙌

Keywords

FAQs

Package last updated on 09 Apr 2018

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