Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tua-body-scroll-lock

Package Overview
Dependencies
Maintainers
2
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tua-body-scroll-lock - npm Package Compare versions

Comparing version 1.1.0-0 to 1.1.0-1

4

dist/index.d.ts

@@ -1,3 +0,3 @@

declare const lock: (targetElements?: HTMLElement[] | undefined) => void;
declare const unlock: (targetElements?: HTMLElement[] | undefined) => void;
declare const lock: (targetElement?: HTMLElement | HTMLElement[] | null | undefined) => void;
declare const unlock: (targetElement?: HTMLElement | HTMLElement[] | null | undefined) => void;
export { lock, unlock };
/**
* tua-body-scroll-lock v1.1.0-0
* tua-body-scroll-lock v1.1.0-1
* (c) 2020 Evinma, BuptStEve

@@ -8,3 +8,2 @@ * @license MIT

const isServer = () => typeof window === 'undefined';
const $ = (selector) => document.querySelector(selector);
const detectOS = (ua) => {

@@ -54,5 +53,5 @@ ua = ua || navigator.userAgent;

const setOverflowHiddenPc = () => {
const $body = $('body');
const $body = document.body;
const bodyStyle = Object.assign({}, $body.style);
const scrollBarWidth = window.innerWidth - document.body.clientWidth;
const scrollBarWidth = window.innerWidth - $body.clientWidth;
$body.style.overflow = 'hidden';

@@ -68,4 +67,4 @@ $body.style.boxSizing = 'border-box';

const setOverflowHiddenMobile = () => {
const $html = $('html');
const $body = $('body');
const $html = document.documentElement;
const $body = document.body;
const scrollTop = $html.scrollTop || $body.scrollTop;

@@ -113,18 +112,18 @@ const htmlStyle = Object.assign({}, $html.style);

};
const checkTargetElement = (targetElements) => {
if (targetElements)
const checkTargetElement = (targetElement) => {
if (targetElement)
return;
if (targetElements === null)
if (targetElement === null)
return;
console.warn(`If scrolling is also required in the floating layer, ` +
`the targetElements must be provided.`);
`the target element must be provided.`);
};
const lock = (targetElements) => {
const lock = (targetElement) => {
if (isServer())
return;
checkTargetElement(targetElements);
checkTargetElement(targetElement);
if (detectOS().ios) {
// iOS
if (targetElements) {
const elementArray = Array.isArray(targetElements) ? targetElements : [targetElements];
if (targetElement) {
const elementArray = Array.isArray(targetElement) ? targetElement : [targetElement];
elementArray.forEach((element) => {

@@ -157,6 +156,6 @@ if (element && lockedElements.indexOf(element) === -1) {

};
const unlock = (targetElements) => {
const unlock = (targetElement) => {
if (isServer())
return;
checkTargetElement(targetElements);
checkTargetElement(targetElement);
lockedNum -= 1;

@@ -171,4 +170,4 @@ if (lockedNum > 0)

// iOS
if (targetElements) {
const elementArray = Array.isArray(targetElements) ? targetElements : [targetElements];
if (targetElement) {
const elementArray = Array.isArray(targetElement) ? targetElement : [targetElement];
elementArray.forEach((element) => {

@@ -175,0 +174,0 @@ const index = lockedElements.indexOf(element);

@@ -1,1 +0,1 @@

const e=()=>"undefined"==typeof window,t=e=>document.querySelector(e),o=e=>{e=e||navigator.userAgent;const t=/(iPad).*OS\s([\d_]+)/.test(e);return{ios:!t&&/(iPhone\sOS)\s([\d_]+)/.test(e)||t,android:/(Android);?[\s\/]+([\d.]+)?/.test(e)}};let i=0,n=0,s=0,r=null,l=!1;const c=[],d=function(t){if(e())return!1;if(!t)throw new Error("options must be provided");let o=!1;const i={get passive(){o=!0}},n=()=>{};window.addEventListener("__TUA_BSL_TEST_PASSIVE__",n,i),window.removeEventListener("__TUA_BSL_TEST_PASSIVE__",n,i);const{capture:s}=t;return o?t:void 0!==s&&s}({passive:!1}),h=e=>{e.cancelable&&e.preventDefault()},a=a=>{if(!e()){if(o().ios){if(a){(Array.isArray(a)?a:[a]).forEach(e=>{e&&-1===c.indexOf(e)&&(e.ontouchstart=e=>{n=e.targetTouches[0].clientY,s=e.targetTouches[0].clientX},e.ontouchmove=t=>{1===t.targetTouches.length&&((e,t)=>{if(t){const{scrollTop:o,scrollLeft:i,scrollWidth:r,scrollHeight:l,clientWidth:c,clientHeight:d}=t,a=e.targetTouches[0].clientX-s,u=e.targetTouches[0].clientY-n,f=Math.abs(u)>Math.abs(a),y=u>0&&0===o,g=a>0&&0===i,p=a<0&&i+c+1>=r,v=u<0&&o+d+1>=l;if(f&&(y||v)||!f&&(g||p))return h(e)}e.stopPropagation()})(t,e)},c.push(e))})}l||(document.addEventListener("touchmove",h,d),l=!0)}else i<=0&&(r=o().android?(()=>{const e=t("html"),o=t("body"),i=e.scrollTop||o.scrollTop,n=Object.assign({},e.style),s=Object.assign({},o.style);return e.style.height="100%",e.style.overflow="hidden",o.style.top=`-${i}px`,o.style.width="100%",o.style.height="auto",o.style.position="fixed",o.style.overflow="hidden",()=>{e.style.height=n.height||"",e.style.overflow=n.overflow||"",["top","width","height","overflow","position"].forEach(e=>{o.style[e]=s[e]||""}),window.scrollTo(0,i)}})():(()=>{const e=t("body"),o=Object.assign({},e.style),i=window.innerWidth-document.body.clientWidth;return e.style.overflow="hidden",e.style.boxSizing="border-box",e.style.paddingRight=`${i}px`,()=>{["overflow","boxSizing","paddingRight"].forEach(t=>{e.style[t]=o[t]||""})}})());i+=1}},u=t=>{if(!(e()||(i-=1)>0))if(o().ios||"function"!=typeof r){if(t){(Array.isArray(t)?t:[t]).forEach(e=>{const t=c.indexOf(e);-1!==t&&(e.ontouchmove=null,e.ontouchstart=null,c.splice(t,1))})}l&&(document.removeEventListener("touchmove",h,d),l=!1)}else r()};export{a as lock,u as unlock};
const e=()=>"undefined"==typeof window,t=e=>{e=e||navigator.userAgent;const t=/(iPad).*OS\s([\d_]+)/.test(e);return{ios:!t&&/(iPhone\sOS)\s([\d_]+)/.test(e)||t,android:/(Android);?[\s\/]+([\d.]+)?/.test(e)}};let o=0,n=0,i=0,s=null,r=!1;const l=[],c=function(t){if(e())return!1;if(!t)throw new Error("options must be provided");let o=!1;const n={get passive(){o=!0}},i=()=>{};window.addEventListener("__TUA_BSL_TEST_PASSIVE__",i,n),window.removeEventListener("__TUA_BSL_TEST_PASSIVE__",i,n);const{capture:s}=t;return o?t:void 0!==s&&s}({passive:!1}),d=e=>{e.cancelable&&e.preventDefault()},h=h=>{if(!e()){if(t().ios){if(h){(Array.isArray(h)?h:[h]).forEach(e=>{e&&-1===l.indexOf(e)&&(e.ontouchstart=e=>{n=e.targetTouches[0].clientY,i=e.targetTouches[0].clientX},e.ontouchmove=t=>{1===t.targetTouches.length&&((e,t)=>{if(t){const{scrollTop:o,scrollLeft:s,scrollWidth:r,scrollHeight:l,clientWidth:c,clientHeight:h}=t,a=e.targetTouches[0].clientX-i,u=e.targetTouches[0].clientY-n,f=Math.abs(u)>Math.abs(a),g=u>0&&0===o,y=a>0&&0===s,p=a<0&&s+c+1>=r,v=u<0&&o+h+1>=l;if(f&&(g||v)||!f&&(y||p))return d(e)}e.stopPropagation()})(t,e)},l.push(e))})}r||(document.addEventListener("touchmove",d,c),r=!0)}else o<=0&&(s=t().android?(()=>{const e=document.documentElement,t=document.body,o=e.scrollTop||t.scrollTop,n=Object.assign({},e.style),i=Object.assign({},t.style);return e.style.height="100%",e.style.overflow="hidden",t.style.top=`-${o}px`,t.style.width="100%",t.style.height="auto",t.style.position="fixed",t.style.overflow="hidden",()=>{e.style.height=n.height||"",e.style.overflow=n.overflow||"",["top","width","height","overflow","position"].forEach(e=>{t.style[e]=i[e]||""}),window.scrollTo(0,o)}})():(()=>{const e=document.body,t=Object.assign({},e.style),o=window.innerWidth-e.clientWidth;return e.style.overflow="hidden",e.style.boxSizing="border-box",e.style.paddingRight=`${o}px`,()=>{["overflow","boxSizing","paddingRight"].forEach(o=>{e.style[o]=t[o]||""})}})());o+=1}},a=n=>{if(!(e()||(o-=1)>0))if(t().ios||"function"!=typeof s){if(n){(Array.isArray(n)?n:[n]).forEach(e=>{const t=l.indexOf(e);-1!==t&&(e.ontouchmove=null,e.ontouchstart=null,l.splice(t,1))})}r&&(document.removeEventListener("touchmove",d,c),r=!1)}else s()};export{h as lock,a as unlock};
/**
* tua-body-scroll-lock v1.1.0-0
* tua-body-scroll-lock v1.1.0-1
* (c) 2020 Evinma, BuptStEve

@@ -10,5 +10,2 @@ * @license MIT

};
var $ = function $(selector) {
return document.querySelector(selector);
};
var detectOS = function detectOS(ua) {

@@ -65,5 +62,5 @@ ua = ua || navigator.userAgent;

var setOverflowHiddenPc = function setOverflowHiddenPc() {
var $body = $('body');
var $body = document.body;
var bodyStyle = Object.assign({}, $body.style);
var scrollBarWidth = window.innerWidth - document.body.clientWidth;
var scrollBarWidth = window.innerWidth - $body.clientWidth;
$body.style.overflow = 'hidden';

@@ -80,4 +77,4 @@ $body.style.boxSizing = 'border-box';

var setOverflowHiddenMobile = function setOverflowHiddenMobile() {
var $html = $('html');
var $body = $('body');
var $html = document.documentElement;
var $body = document.body;
var scrollTop = $html.scrollTop || $body.scrollTop;

@@ -133,17 +130,17 @@ var htmlStyle = Object.assign({}, $html.style);

var checkTargetElement = function checkTargetElement(targetElements) {
if (targetElements) return;
if (targetElements === null) return;
var checkTargetElement = function checkTargetElement(targetElement) {
if (targetElement) return;
if (targetElement === null) return;
if (process.env.NODE_ENV === 'production') return;
console.warn("If scrolling is also required in the floating layer, " + "the targetElements must be provided.");
console.warn("If scrolling is also required in the floating layer, " + "the target element must be provided.");
};
var lock = function lock(targetElements) {
var lock = function lock(targetElement) {
if (isServer()) return;
checkTargetElement(targetElements);
checkTargetElement(targetElement);
if (detectOS().ios) {
// iOS
if (targetElements) {
var elementArray = Array.isArray(targetElements) ? targetElements : [targetElements];
if (targetElement) {
var elementArray = Array.isArray(targetElement) ? targetElement : [targetElement];
elementArray.forEach(function (element) {

@@ -177,5 +174,5 @@ if (element && lockedElements.indexOf(element) === -1) {

var unlock = function unlock(targetElements) {
var unlock = function unlock(targetElement) {
if (isServer()) return;
checkTargetElement(targetElements);
checkTargetElement(targetElement);
lockedNum -= 1;

@@ -190,4 +187,4 @@ if (lockedNum > 0) return;

if (targetElements) {
var elementArray = Array.isArray(targetElements) ? targetElements : [targetElements];
if (targetElement) {
var elementArray = Array.isArray(targetElement) ? targetElement : [targetElement];
elementArray.forEach(function (element) {

@@ -194,0 +191,0 @@ var index = lockedElements.indexOf(element);

/**
* tua-body-scroll-lock v1.1.0-0
* tua-body-scroll-lock v1.1.0-1
* (c) 2020 Evinma, BuptStEve

@@ -16,5 +16,2 @@ * @license MIT

};
var $ = function $(selector) {
return document.querySelector(selector);
};
var detectOS = function detectOS(ua) {

@@ -71,5 +68,5 @@ ua = ua || navigator.userAgent;

var setOverflowHiddenPc = function setOverflowHiddenPc() {
var $body = $('body');
var $body = document.body;
var bodyStyle = Object.assign({}, $body.style);
var scrollBarWidth = window.innerWidth - document.body.clientWidth;
var scrollBarWidth = window.innerWidth - $body.clientWidth;
$body.style.overflow = 'hidden';

@@ -86,4 +83,4 @@ $body.style.boxSizing = 'border-box';

var setOverflowHiddenMobile = function setOverflowHiddenMobile() {
var $html = $('html');
var $body = $('body');
var $html = document.documentElement;
var $body = document.body;
var scrollTop = $html.scrollTop || $body.scrollTop;

@@ -139,16 +136,16 @@ var htmlStyle = Object.assign({}, $html.style);

var checkTargetElement = function checkTargetElement(targetElements) {
if (targetElements) return;
if (targetElements === null) return;
console.warn("If scrolling is also required in the floating layer, " + "the targetElements must be provided.");
var checkTargetElement = function checkTargetElement(targetElement) {
if (targetElement) return;
if (targetElement === null) return;
console.warn("If scrolling is also required in the floating layer, " + "the target element must be provided.");
};
var lock = function lock(targetElements) {
var lock = function lock(targetElement) {
if (isServer()) return;
checkTargetElement(targetElements);
checkTargetElement(targetElement);
if (detectOS().ios) {
// iOS
if (targetElements) {
var elementArray = Array.isArray(targetElements) ? targetElements : [targetElements];
if (targetElement) {
var elementArray = Array.isArray(targetElement) ? targetElement : [targetElement];
elementArray.forEach(function (element) {

@@ -182,5 +179,5 @@ if (element && lockedElements.indexOf(element) === -1) {

var unlock = function unlock(targetElements) {
var unlock = function unlock(targetElement) {
if (isServer()) return;
checkTargetElement(targetElements);
checkTargetElement(targetElement);
lockedNum -= 1;

@@ -195,4 +192,4 @@ if (lockedNum > 0) return;

if (targetElements) {
var elementArray = Array.isArray(targetElements) ? targetElements : [targetElements];
if (targetElement) {
var elementArray = Array.isArray(targetElement) ? targetElement : [targetElement];
elementArray.forEach(function (element) {

@@ -199,0 +196,0 @@ var index = lockedElements.indexOf(element);

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).bodyScrollLock={})}(this,function(e){"use strict";var t=function(){return"undefined"==typeof window},o=function(e){return document.querySelector(e)},n=function(e){e=e||navigator.userAgent;var t=/(iPad).*OS\s([\d_]+)/.test(e);return{ios:!t&&/(iPhone\sOS)\s([\d_]+)/.test(e)||t,android:/(Android);?[\s\/]+([\d.]+)?/.test(e)}};var i=0,r=0,s=0,c=null,l=!1,d=[],u=function(e){if(t())return!1;if(!e)throw new Error("options must be provided");var o=!1,n={get passive(){o=!0}},i=function(){};window.addEventListener("__TUA_BSL_TEST_PASSIVE__",i,n),window.removeEventListener("__TUA_BSL_TEST_PASSIVE__",i,n);var r=e.capture;return o?e:void 0!==r&&r}({passive:!1}),f=function(e){e.cancelable&&e.preventDefault()};e.lock=function(e){if(!t()){if(n().ios){if(e)(Array.isArray(e)?e:[e]).forEach(function(e){e&&-1===d.indexOf(e)&&(e.ontouchstart=function(e){r=e.targetTouches[0].clientY,s=e.targetTouches[0].clientX},e.ontouchmove=function(t){1===t.targetTouches.length&&function(e,t){if(t){var o=t.scrollTop,n=t.scrollLeft,i=t.scrollWidth,c=t.scrollHeight,l=t.clientWidth,d=t.clientHeight,u=e.targetTouches[0].clientX-s,a=e.targetTouches[0].clientY-r,h=Math.abs(a)>Math.abs(u);if(h&&(a>0&&0===o||a<0&&o+d+1>=c)||!h&&(u>0&&0===n||u<0&&n+l+1>=i))return f(e)}e.stopPropagation()}(t,e)},d.push(e))});l||(document.addEventListener("touchmove",f,u),l=!0)}else i<=0&&(c=n().android?(a=o("html"),h=o("body"),v=a.scrollTop||h.scrollTop,y=Object.assign({},a.style),p=Object.assign({},h.style),a.style.height="100%",a.style.overflow="hidden",h.style.top="-".concat(v,"px"),h.style.width="100%",h.style.height="auto",h.style.position="fixed",h.style.overflow="hidden",function(){a.style.height=y.height||"",a.style.overflow=y.overflow||"",["top","width","height","overflow","position"].forEach(function(e){h.style[e]=p[e]||""}),window.scrollTo(0,v)}):function(){var e=o("body"),t=Object.assign({},e.style),n=window.innerWidth-document.body.clientWidth;return e.style.overflow="hidden",e.style.boxSizing="border-box",e.style.paddingRight="".concat(n,"px"),function(){["overflow","boxSizing","paddingRight"].forEach(function(o){e.style[o]=t[o]||""})}}());var a,h,v,y,p;i+=1}},e.unlock=function(e){if(!(t()||(i-=1)>0))if(n().ios||"function"!=typeof c){if(e)(Array.isArray(e)?e:[e]).forEach(function(e){var t=d.indexOf(e);-1!==t&&(e.ontouchmove=null,e.ontouchstart=null,d.splice(t,1))});l&&(document.removeEventListener("touchmove",f,u),l=!1)}else c()},Object.defineProperty(e,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).bodyScrollLock={})}(this,function(t){"use strict";var e=function(){return"undefined"==typeof window},o=function(t){t=t||navigator.userAgent;var e=/(iPad).*OS\s([\d_]+)/.test(t);return{ios:!e&&/(iPhone\sOS)\s([\d_]+)/.test(t)||e,android:/(Android);?[\s\/]+([\d.]+)?/.test(t)}};var n=0,i=0,r=0,s=null,c=!1,l=[],d=function(t){if(e())return!1;if(!t)throw new Error("options must be provided");var o=!1,n={get passive(){o=!0}},i=function(){};window.addEventListener("__TUA_BSL_TEST_PASSIVE__",i,n),window.removeEventListener("__TUA_BSL_TEST_PASSIVE__",i,n);var r=t.capture;return o?t:void 0!==r&&r}({passive:!1}),u=function(t){t.cancelable&&t.preventDefault()};t.lock=function(t){if(!e()){var f,a,h,v,p;o().ios?(t&&(Array.isArray(t)?t:[t]).forEach(function(t){t&&-1===l.indexOf(t)&&(t.ontouchstart=function(t){i=t.targetTouches[0].clientY,r=t.targetTouches[0].clientX},t.ontouchmove=function(e){1===e.targetTouches.length&&function(t,e){if(e){var o=e.scrollTop,n=e.scrollLeft,s=e.scrollWidth,c=e.scrollHeight,l=e.clientWidth,d=e.clientHeight,f=t.targetTouches[0].clientX-r,a=t.targetTouches[0].clientY-i,h=Math.abs(a)>Math.abs(f);if(h&&(a>0&&0===o||a<0&&o+d+1>=c)||!h&&(f>0&&0===n||f<0&&n+l+1>=s))return u(t)}t.stopPropagation()}(e,t)},l.push(t))}),c||(document.addEventListener("touchmove",u,d),c=!0)):n<=0&&(s=o().android?(f=document.documentElement,a=document.body,h=f.scrollTop||a.scrollTop,v=Object.assign({},f.style),p=Object.assign({},a.style),f.style.height="100%",f.style.overflow="hidden",a.style.top="-".concat(h,"px"),a.style.width="100%",a.style.height="auto",a.style.position="fixed",a.style.overflow="hidden",function(){f.style.height=v.height||"",f.style.overflow=v.overflow||"",["top","width","height","overflow","position"].forEach(function(t){a.style[t]=p[t]||""}),window.scrollTo(0,h)}):function(){var t=document.body,e=Object.assign({},t.style),o=window.innerWidth-t.clientWidth;return t.style.overflow="hidden",t.style.boxSizing="border-box",t.style.paddingRight="".concat(o,"px"),function(){["overflow","boxSizing","paddingRight"].forEach(function(o){t.style[o]=e[o]||""})}}()),n+=1}},t.unlock=function(t){e()||(n-=1)>0||(o().ios||"function"!=typeof s?(t&&(Array.isArray(t)?t:[t]).forEach(function(t){var e=l.indexOf(t);-1!==e&&(t.ontouchmove=null,t.ontouchstart=null,l.splice(e,1))}),c&&(document.removeEventListener("touchmove",u,d),c=!1)):s())},Object.defineProperty(t,"__esModule",{value:!0})});
export declare const isServer: () => boolean;
export declare const $: (selector: string) => HTMLElement;
export interface DetectOSResult {

@@ -4,0 +3,0 @@ ios: boolean;

{
"name": "tua-body-scroll-lock",
"version": "1.1.0-0",
"version": "1.1.0-1",
"description": "🔐Body scroll locking that just works with everything",

@@ -5,0 +5,0 @@ "main": "dist/tua-bsl.umd.js",

@@ -134,4 +134,4 @@ # tua-body-scroll-lock

### TargetElements needs scrolling(iOS only)
In some scenarios, when scrolling is prohibited, some elements still need to scroll, at this point, pass the targetElements.
### TargetElement needs scrolling(iOS only)
In some scenarios, when scrolling is prohibited, some elements still need to scroll, at this point, pass the targetElement.

@@ -143,9 +143,14 @@ ```js

// one targetElement
const targetElement = elementOne
// multiple targetElements
const targetElements = [elementOne, elementTwo]
lock(targetElement)
lock(targetElements)
unlock(targetElement)
unlock(targetElements)
```
> The `targetElements` is not required on the PC and Android.
> The `targetElement` is not required on the PC and Android.

@@ -169,7 +174,19 @@ ## Demo

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
<table><tr><td align="center"><a href="https://github.com/evinma"><img src="https://avatars2.githubusercontent.com/u/16096567?v=4" width="100px;" alt="evinma"/><br /><sub><b>evinma</b></sub></a><br /><a href="https://github.com/tuateam/tua-body-scroll-lock/commits?author=evinma" title="Code">💻</a> <a href="https://github.com/tuateam/tua-body-scroll-lock/commits?author=evinma" title="Documentation">📖</a> <a href="#infra-evinma" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#translation-evinma" title="Translation">🌍</a></td><td align="center"><a href="https://buptsteve.github.io"><img src="https://avatars2.githubusercontent.com/u/11501493?v=4" width="100px;" alt="StEve Young"/><br /><sub><b>StEve Young</b></sub></a><br /><a href="https://github.com/tuateam/tua-body-scroll-lock/commits?author=BuptStEve" title="Code">💻</a> <a href="https://github.com/tuateam/tua-body-scroll-lock/commits?author=BuptStEve" title="Documentation">📖</a> <a href="#infra-BuptStEve" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#translation-BuptStEve" title="Translation">🌍</a></td><td align="center"><a href="https://github.com/li2go"><img src="https://avatars2.githubusercontent.com/u/11485337?v=4" width="100px;" alt="li2go"/><br /><sub><b>li2go</b></sub></a><br /><a href="https://github.com/tuateam/tua-body-scroll-lock/commits?author=li2go" title="Code">💻</a> <a href="https://github.com/tuateam/tua-body-scroll-lock/issues?q=author%3Ali2go" title="Bug reports">🐛</a></td><td align="center"><a href="https://github.com/feitiange"><img src="https://avatars3.githubusercontent.com/u/7125157?v=4" width="100px;" alt="songyan,Wang"/><br /><sub><b>songyan,Wang</b></sub></a><br /><a href="https://github.com/tuateam/tua-body-scroll-lock/commits?author=feitiange" title="Code">💻</a> <a href="https://github.com/tuateam/tua-body-scroll-lock/issues?q=author%3Afeitiange" title="Bug reports">🐛</a></td><td align="center"><a href="https://grawl.ru/"><img src="https://avatars2.githubusercontent.com/u/846774?v=4" width="100px;" alt="Даниил Пронин"/><br /><sub><b>Даниил Пронин</b></sub></a><br /><a href="https://github.com/tuateam/tua-body-scroll-lock/issues?q=author%3AGrawl" title="Bug reports">🐛</a></td></tr></table>
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://github.com/evinma"><img src="https://avatars2.githubusercontent.com/u/16096567?v=4" width="100px;" alt=""/><br /><sub><b>evinma</b></sub></a><br /><a href="https://github.com/tuateam/tua-body-scroll-lock/commits?author=evinma" title="Code">💻</a> <a href="https://github.com/tuateam/tua-body-scroll-lock/commits?author=evinma" title="Documentation">📖</a> <a href="#infra-evinma" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#translation-evinma" title="Translation">🌍</a></td>
<td align="center"><a href="https://buptsteve.github.io"><img src="https://avatars2.githubusercontent.com/u/11501493?v=4" width="100px;" alt=""/><br /><sub><b>StEve Young</b></sub></a><br /><a href="https://github.com/tuateam/tua-body-scroll-lock/commits?author=BuptStEve" title="Code">💻</a> <a href="https://github.com/tuateam/tua-body-scroll-lock/commits?author=BuptStEve" title="Documentation">📖</a> <a href="#infra-BuptStEve" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#translation-BuptStEve" title="Translation">🌍</a></td>
<td align="center"><a href="https://github.com/li2go"><img src="https://avatars2.githubusercontent.com/u/11485337?v=4" width="100px;" alt=""/><br /><sub><b>li2go</b></sub></a><br /><a href="https://github.com/tuateam/tua-body-scroll-lock/commits?author=li2go" title="Code">💻</a> <a href="https://github.com/tuateam/tua-body-scroll-lock/issues?q=author%3Ali2go" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/feitiange"><img src="https://avatars3.githubusercontent.com/u/7125157?v=4" width="100px;" alt=""/><br /><sub><b>songyan,Wang</b></sub></a><br /><a href="https://github.com/tuateam/tua-body-scroll-lock/commits?author=feitiange" title="Code">💻</a> <a href="https://github.com/tuateam/tua-body-scroll-lock/issues?q=author%3Afeitiange" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://grawl.ru/"><img src="https://avatars2.githubusercontent.com/u/846774?v=4" width="100px;" alt=""/><br /><sub><b>Даниил Пронин</b></sub></a><br /><a href="https://github.com/tuateam/tua-body-scroll-lock/issues?q=author%3AGrawl" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/magic-akari"><img src="https://avatars0.githubusercontent.com/u/7829098?v=4" width="100px;" alt=""/><br /><sub><b>阿卡琳</b></sub></a><br /><a href="https://github.com/tuateam/tua-body-scroll-lock/issues?q=author%3Amagic-akari" title="Bug reports">🐛</a></td>
</tr>
</table>
<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
import {
$,
isServer,

@@ -10,2 +9,3 @@ detectOS,

type OverflowHiddenMobileStyleType = 'top' | 'width' | 'height' | 'overflow' | 'position'
type Nullable<T> = T | Array<T> | null

@@ -22,5 +22,5 @@ let lockedNum = 0

const setOverflowHiddenPc = () => {
const $body = $('body')
const $body = document.body
const bodyStyle = { ...$body.style }
const scrollBarWidth = window.innerWidth - document.body.clientWidth
const scrollBarWidth = window.innerWidth - $body.clientWidth

@@ -39,4 +39,4 @@ $body.style.overflow = 'hidden'

const setOverflowHiddenMobile = () => {
const $html = $('html')
const $body = $('body')
const $html = document.documentElement
const $body = document.body
const scrollTop = $html.scrollTop || $body.scrollTop

@@ -104,5 +104,5 @@ const htmlStyle = { ...$html.style }

const checkTargetElement = (targetElements?: Array<HTMLElement>) => {
if (targetElements) return
if (targetElements === null) return
const checkTargetElement = (targetElement?: Nullable<HTMLElement>) => {
if (targetElement) return
if (targetElement === null) return
if (process.env.NODE_ENV === 'production') return

@@ -112,17 +112,17 @@

`If scrolling is also required in the floating layer, ` +
`the targetElements must be provided.`
`the target element must be provided.`
)
}
const lock = (targetElements?: Array<HTMLElement>) => {
const lock = (targetElement?: Nullable<HTMLElement>) => {
if (isServer()) return
checkTargetElement(targetElements)
checkTargetElement(targetElement)
if (detectOS().ios) {
// iOS
if (targetElements) {
const elementArray = Array.isArray(targetElements) ? targetElements : [targetElements]
if (targetElement) {
const elementArray = Array.isArray(targetElement) ? targetElement : [targetElement]
elementArray.forEach((element: HTMLElement) => {
elementArray.forEach((element) => {
if (element && lockedElements.indexOf(element) === -1) {

@@ -158,6 +158,6 @@ element.ontouchstart = (event) => {

const unlock = (targetElements?: Array<HTMLElement>) => {
const unlock = (targetElement?: Nullable<HTMLElement>) => {
if (isServer()) return
checkTargetElement(targetElements)
checkTargetElement(targetElement)
lockedNum -= 1

@@ -175,6 +175,6 @@

// iOS
if (targetElements) {
const elementArray = Array.isArray(targetElements) ? targetElements : [targetElements]
if (targetElement) {
const elementArray = Array.isArray(targetElement) ? targetElement : [targetElement]
elementArray.forEach((element: HTMLElement) => {
elementArray.forEach((element) => {
const index = lockedElements.indexOf(element)

@@ -181,0 +181,0 @@

export const isServer = () => typeof window === 'undefined'
export const $ = (selector: string) => <HTMLElement>document.querySelector(selector)
export interface DetectOSResult { ios: boolean, android: boolean }

@@ -6,0 +4,0 @@ export const detectOS = (ua?: string): DetectOSResult => {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc