tua-body-scroll-lock
Advanced tools
Comparing version 0.2.1 to 0.2.2-0
/** | ||
* tua-body-scroll-lock v0.2.1 | ||
* tua-body-scroll-lock v0.2.2-0 | ||
* (c) 2019 Evinma, BuptStEve | ||
@@ -69,2 +69,3 @@ * @license MIT | ||
$body.style.width = '100%'; | ||
$body.style.height = 'auto'; | ||
$body.style.position = 'fixed'; | ||
@@ -71,0 +72,0 @@ $body.style.overflow = 'hidden'; |
@@ -1,1 +0,1 @@ | ||
let e=0,t=0,o=null,n=!1;const i="undefined"==typeof window,s=[],l=!i&&document.querySelector.bind(document);let r;if(!i){const e="__TUA_BSL_TEST_PASSIVE__",t={get passive(){r={passive:!1}}};window.addEventListener(e,null,t),window.removeEventListener(e,null,t)}const d=()=>{const e=navigator.userAgent,t=/(iPad).*OS\s([\d_]+)/.test(e),o=!t&&/(iPhone\sOS)\s([\d_]+)/.test(e),n=/(Android);?[\s\/]+([\d.]+)?/.test(e);return{os:n?"android":"ios",ios:o||t,ipad:t,iphone:o,android:n}},c=e=>{e.cancelable&&e.preventDefault()},h=h=>{i||(d().ios?(h&&-1===s.indexOf(h)&&(h.ontouchstart=e=>{t=e.targetTouches[0].clientY},h.ontouchmove=e=>{1===e.targetTouches.length&&((e,o)=>{const n=e.targetTouches[0].clientY-t;if(o){const{scrollTop:t,scrollHeight:i,clientHeight:s}=o,l=n<0&&t+s+1>=i;if(n>0&&0===t||l)return c(e)}e.stopPropagation()})(e,h)},s.push(h)),n||(document.addEventListener("touchmove",c,r),n=!0)):e<=0&&(o=d().android?(()=>{const e=l("html"),t=l("body"),o=e.scrollTop||t.scrollTop,n={...e.style},i={...t.style};return e.style.height="100%",e.style.overflow="hidden",t.style.top=`-${o}px`,t.style.width="100%",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=l("body"),t={...e.style},o=window.innerWidth-document.body.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]||""})}})()),e+=1)},u=t=>{if(i)return;if((e-=1)>0)return;if(!d().ios)return void(e<=0&&"function"==typeof o&&o());const l=s.indexOf(t);-1!==l&&(t.ontouchmove=null,t.ontouchstart=null,s.splice(l,1)),n&&(document.removeEventListener("touchmove",c,r),n=!1)};export{h as lock,u as unlock}; | ||
let e=0,t=0,o=null,n=!1;const i="undefined"==typeof window,s=[],l=!i&&document.querySelector.bind(document);let r;if(!i){const e="__TUA_BSL_TEST_PASSIVE__",t={get passive(){r={passive:!1}}};window.addEventListener(e,null,t),window.removeEventListener(e,null,t)}const d=()=>{const e=navigator.userAgent,t=/(iPad).*OS\s([\d_]+)/.test(e),o=!t&&/(iPhone\sOS)\s([\d_]+)/.test(e),n=/(Android);?[\s\/]+([\d.]+)?/.test(e);return{os:n?"android":"ios",ios:o||t,ipad:t,iphone:o,android:n}},c=e=>{e.cancelable&&e.preventDefault()},h=h=>{i||(d().ios?(h&&-1===s.indexOf(h)&&(h.ontouchstart=e=>{t=e.targetTouches[0].clientY},h.ontouchmove=e=>{1===e.targetTouches.length&&((e,o)=>{const n=e.targetTouches[0].clientY-t;if(o){const{scrollTop:t,scrollHeight:i,clientHeight:s}=o,l=n<0&&t+s+1>=i;if(n>0&&0===t||l)return c(e)}e.stopPropagation()})(e,h)},s.push(h)),n||(document.addEventListener("touchmove",c,r),n=!0)):e<=0&&(o=d().android?(()=>{const e=l("html"),t=l("body"),o=e.scrollTop||t.scrollTop,n={...e.style},i={...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=l("body"),t={...e.style},o=window.innerWidth-document.body.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]||""})}})()),e+=1)},u=t=>{if(i)return;if((e-=1)>0)return;if(!d().ios)return void(e<=0&&"function"==typeof o&&o());const l=s.indexOf(t);-1!==l&&(t.ontouchmove=null,t.ontouchstart=null,s.splice(l,1)),n&&(document.removeEventListener("touchmove",c,r),n=!1)};export{h as lock,u as unlock}; |
/** | ||
* tua-body-scroll-lock v0.2.1 | ||
* tua-body-scroll-lock v0.2.2-0 | ||
* (c) 2019 Evinma, BuptStEve | ||
@@ -109,2 +109,3 @@ * @license MIT | ||
$body.style.width = '100%'; | ||
$body.style.height = 'auto'; | ||
$body.style.position = 'fixed'; | ||
@@ -111,0 +112,0 @@ $body.style.overflow = 'hidden'; |
/** | ||
* tua-body-scroll-lock v0.2.1 | ||
* tua-body-scroll-lock v0.2.2-0 | ||
* (c) 2019 Evinma, BuptStEve | ||
@@ -115,2 +115,3 @@ * @license MIT | ||
$body.style.width = '100%'; | ||
$body.style.height = 'auto'; | ||
$body.style.position = 'fixed'; | ||
@@ -117,0 +118,0 @@ $body.style.overflow = 'hidden'; |
@@ -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";function t(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function o(e){for(var o=1;o<arguments.length;o++){var n=null!=arguments[o]?arguments[o]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),i.forEach(function(o){t(e,o,n[o])})}return e}var n,i=0,r=0,l=null,c=!1,s="undefined"==typeof window,d=[],u=!s&&document.querySelector.bind(document);if(!s){var f={get passive(){n={passive:!1}}};window.addEventListener("__TUA_BSL_TEST_PASSIVE__",null,f),window.removeEventListener("__TUA_BSL_TEST_PASSIVE__",null,f)}var a=function(){var e=navigator.userAgent,t=/(iPad).*OS\s([\d_]+)/.test(e),o=!t&&/(iPhone\sOS)\s([\d_]+)/.test(e),n=/(Android);?[\s\/]+([\d.]+)?/.test(e);return{os:n?"android":"ios",ios:o||t,ipad:t,iphone:o,android:n}},h=function(e){e.cancelable&&e.preventDefault()};e.lock=function(e){var t,f,p,y,v;s||(a().ios?(e&&-1===d.indexOf(e)&&(e.ontouchstart=function(e){r=e.targetTouches[0].clientY},e.ontouchmove=function(t){1===t.targetTouches.length&&function(e,t){var o=e.targetTouches[0].clientY-r;if(t){var n=t.scrollTop,i=t.scrollHeight,l=t.clientHeight;if(o>0&&0===n||o<0&&n+l+1>=i)return h(e)}e.stopPropagation()}(t,e)},d.push(e)),c||(document.addEventListener("touchmove",h,n),c=!0)):i<=0&&(l=a().android?(t=u("html"),f=u("body"),p=t.scrollTop||f.scrollTop,y=o({},t.style),v=o({},f.style),t.style.height="100%",t.style.overflow="hidden",f.style.top="-".concat(p,"px"),f.style.width="100%",f.style.position="fixed",f.style.overflow="hidden",function(){t.style.height=y.height||"",t.style.overflow=y.overflow||"",["top","width","height","overflow","position"].forEach(function(e){f.style[e]=v[e]||""}),window.scrollTo(0,p)}):function(){var e=u("body"),t=o({},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]||""})}}()),i+=1)},e.unlock=function(e){if(!(s||(i-=1)>0))if(a().ios){var t=d.indexOf(e);-1!==t&&(e.ontouchmove=null,e.ontouchstart=null,d.splice(t,1)),c&&(document.removeEventListener("touchmove",h,n),c=!1)}else i<=0&&"function"==typeof l&&l()},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!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";function t(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function o(e){for(var o=1;o<arguments.length;o++){var n=null!=arguments[o]?arguments[o]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),i.forEach(function(o){t(e,o,n[o])})}return e}var n,i=0,r=0,l=null,c=!1,s="undefined"==typeof window,u=[],d=!s&&document.querySelector.bind(document);if(!s){var f={get passive(){n={passive:!1}}};window.addEventListener("__TUA_BSL_TEST_PASSIVE__",null,f),window.removeEventListener("__TUA_BSL_TEST_PASSIVE__",null,f)}var a=function(){var e=navigator.userAgent,t=/(iPad).*OS\s([\d_]+)/.test(e),o=!t&&/(iPhone\sOS)\s([\d_]+)/.test(e),n=/(Android);?[\s\/]+([\d.]+)?/.test(e);return{os:n?"android":"ios",ios:o||t,ipad:t,iphone:o,android:n}},h=function(e){e.cancelable&&e.preventDefault()};e.lock=function(e){var t,f,y,p,v;s||(a().ios?(e&&-1===u.indexOf(e)&&(e.ontouchstart=function(e){r=e.targetTouches[0].clientY},e.ontouchmove=function(t){1===t.targetTouches.length&&function(e,t){var o=e.targetTouches[0].clientY-r;if(t){var n=t.scrollTop,i=t.scrollHeight,l=t.clientHeight;if(o>0&&0===n||o<0&&n+l+1>=i)return h(e)}e.stopPropagation()}(t,e)},u.push(e)),c||(document.addEventListener("touchmove",h,n),c=!0)):i<=0&&(l=a().android?(t=d("html"),f=d("body"),y=t.scrollTop||f.scrollTop,p=o({},t.style),v=o({},f.style),t.style.height="100%",t.style.overflow="hidden",f.style.top="-".concat(y,"px"),f.style.width="100%",f.style.height="auto",f.style.position="fixed",f.style.overflow="hidden",function(){t.style.height=p.height||"",t.style.overflow=p.overflow||"",["top","width","height","overflow","position"].forEach(function(e){f.style[e]=v[e]||""}),window.scrollTo(0,y)}):function(){var e=d("body"),t=o({},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]||""})}}()),i+=1)},e.unlock=function(e){if(!(s||(i-=1)>0))if(a().ios){var t=u.indexOf(e);-1!==t&&(e.ontouchmove=null,e.ontouchstart=null,u.splice(t,1)),c&&(document.removeEventListener("touchmove",h,n),c=!1)}else i<=0&&"function"==typeof l&&l()},Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "tua-body-scroll-lock", | ||
"version": "0.2.1", | ||
"version": "0.2.2-0", | ||
"description": "🔐Body scroll locking that just works with everything", | ||
@@ -5,0 +5,0 @@ "main": "dist/tua-bsl.umd.js", |
@@ -63,2 +63,3 @@ let lockedNum = 0 | ||
$body.style.width = '100%' | ||
$body.style.height = 'auto' | ||
$body.style.position = 'fixed' | ||
@@ -65,0 +66,0 @@ $body.style.overflow = 'hidden' |
Sorry, the diff of this file is not supported yet
40944
646