Coder Social home page Coder Social logo

jquery-scrollfreeze's Introduction

jquery.scrollfreeze

A simple jQuery plugin that allows you to easily disable(freeze) user scroll events on the window.

Installation

Include script after the jQuery library:

<script src="/path/to/jquery.scrollfreeze.js"></script>

The plugin can also be loaded as an AMD module.

Usage

The plugin automatically initializes on document.ready, and requires no configuration except for one optional setting useOverflow, which I will explain shortly.

To disable(freeze) user scroll:

$.scrollFreeze.freeze();

To renable(thaw) user scroll:

$.scrollFreeze.thaw();

To toggle between disabled and enabled scroll:

$.scrollFreeze.toggle();

By default freeze and thaw will only block user scroll events e.g. Mouse Wheel, arrow keys. The user still has the ability to use the scroll bar to scroll the page by default. To prevent this call the useOverflow method upon page load.

$.scrollFreeze.useOverflow();

To disable plugin, which essentially removes the event listenrs on the plugin:

$.scrollFreeze.disable();

If you need to re-enable after disabling:

$.scrollFreeze.enable();

Some convenience methods to retrieve state:

$.scrollFreeze.isFrozen();
$.scrollFreeze.isEnabled();

Examples

See the demo included for a simple example.

Notes

  • This was never intended for mobile use and therefore was never tested on mobile devices. Although it may work on mobile if useOverflow has been set.
  • This script was created out of necessity when I was working on a single page application that automatically scrolled between sections. I needed to prevent the user's scroll events from interfering with the automated scrolling.

Author

Ryan Johnson

jquery-scrollfreeze's People

Contributors

ryandrewjohnson avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.