vue-lock-scroll

Vue/Nuxt body-scroll-lock implementation
960
Install
npm install vue-lock-scroll
Latest Version:1.0.14
License:MIT
Last Updated:Jul 1, 2019
Links: npm
Maintainer: stas_glebov

Vue lock scroll

Vue/Nuxt body-scroll-lock implementation. Lock body scroll at all devices

NPM Version

Install

npm i -S vue-scroll-lock

Usage

import ScrollLock from 'vue-lock-scroll'

Vue.use(ScrollLock, options)

Options

Property Type Default
propName String $scrollLock
gapedElements String ''

propName - recommended to use with $ prefix to prevent duplicate naming in component.

gapedElements - when scroll locks scrollbar disappears so fixed element position change relative to scrollBar width. To prevent it you can pass gapedElements property with css selectors: '.header, .fixed-div, .absolute-div'.

Example

Vue.use(ScrollLock, {
  propName: '$locker',
  gapedElements: '.header'
})
Lock scroll:
this.$locker.lock(targetElement, options)
Options
this.$locker.lock(targetElement, {
    reserveScrollBarGap: true
})

targetElement - DOM element that can be scrolled.

reserveScrollBarGap - add padding to elements in gapedElements string to prevent content jumping on lock/unlock scroll.

** targetElement required in IOS devices

Unlock scroll with element:
this.$locker.unlock(targetElement)
Unlock all scroll locks:
this.$locker.unlockAll()

Usage outside .vue files

In .js file:

/* import class */
import ScrollLock from 'vue-lock-scroll'

/* create new ScrollLock instance */
const locker = new ScrollLock(gapedElements)

/* example */
const locker = new ScrollLock('.header, .fixed-element')

/* lock scroll */
locker.lock(target, {
  reserveScrollBarGap: true
})

License

MIT

Related Packages

vue-body-scroll-lock

Vue plugin to disable scrolling page. Built on top of https://www.npmjs.com/pack...

6,940 0
scroll-lock-body-2

scroll lock the body and remember the position

8,792 1
vue-focus-lock

It is a trap! (for a focus)

453,610 139
focus-trap-vue

Vue component to trap the focus within a DOM element

3,354,084 217

Version History

Version Released License
1.0.14 MIT
1.0.13 MIT
1.0.12 MIT
1.0.11 MIT
1.0.10 MIT