Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
tua-body-scroll-lock
Advanced tools
inspired by body-scroll-lock
English | 简体中文
tua-body-scroll-lock
enables body scroll locking for everything.
targetElement
targetElement
, even if it's not necessary😱Can't believe it? Please try this demo with BSL yourself.
$ npm i -S tua-body-scroll-lock
# OR
$ yarn add tua-body-scroll-lock
tua-bsl.umd.js
)
<!-- unpkg -->
<script src="https://unpkg.com/tua-body-scroll-lock"></script>
<!-- jsdelivr -->
<script src="https://cdn.jsdelivr.net/npm/tua-body-scroll-lock"></script>
tua-bsl.umd.min.js
)
<!-- unpkg -->
<script src="https://unpkg.com/tua-body-scroll-lock/dist/tua-bsl.umd.min.js"></script>
<!-- jsdelivr -->
<script src="https://cdn.jsdelivr.net/npm/tua-body-scroll-lock/dist/tua-bsl.umd.min.js"></script>
tua-bsl.esm.browser.js
)
<!-- unpkg -->
<script type="module">
import { lock, unlock } from 'https://unpkg.com/tua-body-scroll-lock/dist/tua-bsl.esm.browser.js'
lock()
unlock()
</script>
<!-- jsdelivr -->
<script type="module">
import { lock, unlock } from 'https://cdn.jsdelivr.net/npm/tua-body-scroll-lock/dist/tua-bsl.esm.browser.js'
lock()
unlock()
</script>
tua-bsl.esm.browser.min.js
)
<!-- unpkg -->
<script type="module">
import { lock, unlock } from 'https://unpkg.com/tua-body-scroll-lock/dist/tua-bsl.esm.browser.min.js'
lock()
unlock()
</script>
<!-- jsdelivr -->
<script type="module">
import { lock, unlock } from 'https://cdn.jsdelivr.net/npm/tua-body-scroll-lock/dist/tua-bsl.esm.browser.min.js'
lock()
unlock()
</script>
import { lock, unlock } from 'tua-body-scroll-lock'
lock()
unlock()
In some scenarios, when scrolling is prohibited, some elements still need to scroll, at this point, pass the targetElement.
import { lock, unlock } from 'tua-body-scroll-lock'
const elementOne = document.querySelector('#elementOne')
const elementTwo = document.querySelector('#elementTwo')
// one targetElement
const targetElement = elementOne
// multiple targetElements
const targetElements = [elementOne, elementTwo]
lock(targetElement)
lock(targetElements)
unlock(targetElement)
unlock(targetElements)
The
targetElement
is not required on the PC and Android.
In the SPA, if you called lock
, but forgot to call unlock
before jumping to other pages, that is too bad. Because the operation of the page is not restored, such as forbid touchmove
, clearBodyLocks
is used to clear all side effects. Sure, you can also call unlock
, but if you have called lock
multiple times, you must call unlock
multiple times, which is very unfriendly.
<template>
// some element
</template>
<script>
import { lock, unlock, clearBodyLocks } from 'tua-body-scroll-lock';
export default {
name: 'demo',
data () {
return {}
},
methods: {
showDialog () {
// Disable body scroll
lock()
},
hideDialog () {
// Enable body scroll
unlock()
}
},
beforeDestroy () {
// If forgot to call unlock before jumping to other pages, `clearBodyLocks` can clean all side effect.
clearBodyLocks()
}
}
</script>
platform | link |
---|---|
gh-pages | https://tuateam.github.io/tua-body-scroll-lock |
jsbin | https://jsbin.com/cafiful/edit?output |
codepen | https://codepen.io/buptsteve/pen/PvNQjP |
jsfiddle | https://jsfiddle.net/buptsteve/6u8g3Lf5/ |
codesandbox | https://codesandbox.io/s/o73z4jy5q9 |
Thanks goes to these wonderful people (emoji key):
evinma 💻 📖 🚇 🌍 | StEve Young 💻 📖 🚇 🌍 | li2go 💻 🐛 | songyan,Wang 💻 🐛 | Даниил Пронин 🐛 | 阿卡琳 🐛 |
This project follows the all-contributors specification. Contributions of any kind welcome!
FAQs
🔐Body scroll locking that just works with everything
The npm package tua-body-scroll-lock receives a total of 56,763 weekly downloads. As such, tua-body-scroll-lock popularity was classified as popular.
We found that tua-body-scroll-lock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.