All Projects → BramHoningh → vue-body-scroll-lock

BramHoningh / vue-body-scroll-lock

Licence: other
A Vue directive to lock the body scroll without stopping the target element from scrolling.

Programming Languages

Vue
7211 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to vue-body-scroll-lock

Ng Inline Svg
[Inactive] Angular directive for inserting an SVG file inline within an element.
Stars: ✭ 211 (+603.33%)
Mutual labels:  directive
graphql-directive-rest
GraphQL directive for easy integration with REST API
Stars: ✭ 39 (+30%)
Mutual labels:  directive
angular-simple-slider
An AngularJS directive providing a simple slider functionality
Stars: ✭ 15 (-50%)
Mutual labels:  directive
Vue Scroll
Scroll directive on vue
Stars: ✭ 238 (+693.33%)
Mutual labels:  directive
ngx-access
Add access control to your components using hierarchical configuration with logical expressions.
Stars: ✭ 21 (-30%)
Mutual labels:  directive
angular-ellipsis
A simple lightweight library for Angular which removes excess text and add ellipsis symbol to end of text before text overflows container
Stars: ✭ 16 (-46.67%)
Mutual labels:  directive
Ngx Currency
📦 Currency mask module for Angular
Stars: ✭ 161 (+436.67%)
Mutual labels:  directive
babel-plugin-react-directives
A babel plugin that provides some directives for react(JSX), similar to directives of vue.
Stars: ✭ 80 (+166.67%)
Mutual labels:  directive
ngx-timeago
⏰ Live updating timestamps in Angular 6+
Stars: ✭ 70 (+133.33%)
Mutual labels:  directive
ngx-localstorage
An Angular wrapper for localstorage/sessionstorage access.
Stars: ✭ 27 (-10%)
Mutual labels:  directive
angular-inviewport
A simple lightweight library for Angular with no other dependencies that detects when an element is within the browser viewport and adds a "sn-viewport-in" or "sn-viewport-out" class to the element
Stars: ✭ 72 (+140%)
Mutual labels:  directive
angular-datetime-inputs
📅 Angular directives for datetime inputs
Stars: ✭ 20 (-33.33%)
Mutual labels:  directive
svg-pan-zoom-container
A vanilla-js module for adding zoom-on-wheel and pan-on-drag behavior to inline SVG elements.
Stars: ✭ 31 (+3.33%)
Mutual labels:  directive
Ng Click Outside
[Inactive] Angular directive for handling click events outside of an element.
Stars: ✭ 216 (+620%)
Mutual labels:  directive
angular-paypal-checkout
Angular directive for running PayPal's in-context checkout flow
Stars: ✭ 14 (-53.33%)
Mutual labels:  directive
Ngx Daterangepicker Material
Pure Angular 2+ date range picker with material design theme, a demo here:
Stars: ✭ 169 (+463.33%)
Mutual labels:  directive
angular-cron-gen
A basic way to for users to graphically build a cron expression using Angular.
Stars: ✭ 36 (+20%)
Mutual labels:  directive
angular-scrollspy
A simple lightweight library for Angular which automatically updates links to indicate the currently active section in the viewport
Stars: ✭ 34 (+13.33%)
Mutual labels:  directive
angular-downloader
Angular Downloader is an angularjs directive that enables you to manage browser download - https://720kb.github.io/angular-downloader
Stars: ✭ 16 (-46.67%)
Mutual labels:  directive
ngx-malihu-scrollbar
Angular 2+ scrollbar customization using Malihu jQuery Custom Scrollbar plugin
Stars: ✭ 59 (+96.67%)
Mutual labels:  directive

npm

v-body-scroll-lock

A Vue directive to lock the body from scrolling without stopping the target element from scrolling.
Uses the body-scroll-lock library (https://github.com/willmcpo/body-scroll-lock).
Works on mobile and tablet (iOS, Android) and desktop (Chrome, Firefox, Safari).

Table of Contents

Installation

Yarn

yarn add v-body-scroll-lock

Npm

npm i v-body-scroll-lock --save

Install the Vue plugin

In your main JS file first import this plugin

import VBodyScrollLock from 'v-body-scroll-lock'

Install the plugin

Vue.use(VBodyScrollLock)

How to use

Add v-body-scroll-lock or v-bsl (short version) to the element which you want to keep scrollable.
v-body-scroll-lock and v-bsl take a boolean as an argument like v-body-scroll-lock="modalIsOpen"
If modalIsOpen is true, body scroll lock will be applied to other elements except for the one which has v-body-scroll-lock="modalIsOpen"

Code

For a more deep example checkout App.vue in /src/App.vue.

<template>
    <div 
         v-body-scroll-lock="modalIsOpen"  
         v-show="modalIsOpen" 
         class="modal"
    >
         <p>This is a modal! I am scrollable while the body is not!</p>
         <button @click="closeModal">Close modal</button>
    </div>
</template>
<script>
export default {
    name: 'modal',
    data() {
        return {
            modalIsOpen: false,   
        }
    },
    methods: {
        closeModal() {
            this.$set(this, 'modalIsOpen', false)
        },
        openModal() {
            this.$set(this, 'modalIsOpen', true)
        }
    }
}
</script>

Options

reserveScrollBarGap

Reserves the width of the scrollbar and prevents the unpleasant flickering effect that can occur when locking the body scroll.
More info here.

To enable the reserveScrollBarGap option add :reserve-scroll-bar-gap after v-body-scroll-lock or v-bsl.
Example: v-body-scroll-lock:reserve-scroll-bar-gap="modalIsOpen".

Issues

Issues can be created on the issues page.

Contributing

To contribute, please make a pull request.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].