Giter Site home page Giter Site logo

capsid-scroll-lock's Introduction

capsid-scroll-lock v2.0.0

CircleCI codecov

๐Ÿ—œ๏ธ Body Scroll Lock as capsid module ๐Ÿ’Š

Usage

Install via npm:

npm i --save-dev capsid capsid-scroll-lock

Install it to capsid.

capsid.install(require('capsid-scroll-lock'))

Then, add scroll-lock class to your body tag.

<body class="scroll-lock">
  ...
</body>

Then dispatch capsid-scroll-lock/LOCK custom DOM event to lock the scroll of body and capsid-scroll-lock/UNLOCK event to unlock it.

document.body.dispatchEvent(new CustomEvent('capsid-scroll-lock/LOCK'))

This locks the body scroll.

document.body.dispatchEvent(new CustomEvent('capsid-scroll-lock/UNLOCK'))

The above unlocks the body scroll.

Those event names are available as LOCK and UNLOCK values from the module.

const { LOCK, UNLOCK } = require('capsid-scroll-lock')

console.log(LOCK) // => "capsid-scroll-lock/LOCK"
console.log(UNLOCK) // => "capsid-scroll-lock/UNLOCK"

Example

If you use vanilla.js

const { LOCK, UNLOCK } = require('capsid-scroll-lock')

document.body.dispatchEvent(new CustomEvent(LOCK))
document.body.dispatchEvent(new CustomEvent(UNLOCK))

If you use capsid.js

const { LOCK, UNLOCK } = require('capsid-scroll-lock')
const { component, emits } = require('capsid')

@component('my-component')
class MyComponent {
  @emits(LOCK)
  lockMethod () { ... }

  @emits(UNLOCK)
  unlockMethod () { ... }
}

And put my-component somewhere in body

<body class="scroll-lock">
  ...
  <div class="my-component">
  </div>
  ...
</body>

Then invoking lockMethod locks the body and unlockMethod unlocks the body.

API

const { install, LOCK, UNLOCK } = require('capsid-scroll-lock')

install(capsid, { name })

  • @param capsid - The capsid object
  • @param {string} name - The name of scroll-lock class. Default scroll-lock.

Installs the module to capsid.

require('capsid-scroll-lock').install(capsid, { name: 'my-scroll-lock' })

Alternatively you can call it like:

capsid.install(require('capsid-scroll-lock'), { name: 'my-scroll-lock' })

LOCK, UNLOCK

const LOCK = 'capsid-scroll-lock/LOCK'
const UNLOCK = 'capsid-scroll-lock/UNLOCK'

These are custom event names for locking and unlocking the body scroll.

License

MIT

capsid-scroll-lock's People

Contributors

greenkeeper[bot] avatar kt3k avatar

Stargazers

 avatar  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.