diff --git a/lib/bodyScrollLock.es6.js b/lib/bodyScrollLock.es6.js index fa4f42b9..52b05855 100644 --- a/lib/bodyScrollLock.es6.js +++ b/lib/bodyScrollLock.es6.js @@ -113,7 +113,7 @@ const setPositionFixed = () => window.requestAnimationFrame(() => { const bottomBarHeight = innerHeight - window.innerHeight; if (bottomBarHeight && scrollY >= innerHeight) { // Move the content further up so that the bottom bar doesn't hide it - document.body.style.top = -(scrollY + bottomBarHeight); + document.body.style.top = `-${scrollY + bottomBarHeight}px`; } }), 300); } diff --git a/lib/bodyScrollLock.esm.js b/lib/bodyScrollLock.esm.js index 23518372..6d3df141 100644 --- a/lib/bodyScrollLock.esm.js +++ b/lib/bodyScrollLock.esm.js @@ -121,7 +121,7 @@ var setPositionFixed = function setPositionFixed() { var bottomBarHeight = innerHeight - window.innerHeight; if (bottomBarHeight && scrollY >= innerHeight) { // Move the content further up so that the bottom bar doesn't hide it - document.body.style.top = -(scrollY + bottomBarHeight); + document.body.style.top = '-' + (scrollY + bottomBarHeight) + 'px'; } }); }, 300); diff --git a/lib/bodyScrollLock.js b/lib/bodyScrollLock.js index a8dfa1f1..653fc0e8 100644 --- a/lib/bodyScrollLock.js +++ b/lib/bodyScrollLock.js @@ -150,7 +150,7 @@ var bottomBarHeight = innerHeight - window.innerHeight; if (bottomBarHeight && scrollY >= innerHeight) { // Move the content further up so that the bottom bar doesn't hide it - document.body.style.top = -(scrollY + bottomBarHeight); + document.body.style.top = '-' + (scrollY + bottomBarHeight) + 'px'; } }); }, 300); diff --git a/lib/bodyScrollLock.min.js b/lib/bodyScrollLock.min.js index c2f200f5..7a2c1b78 100644 --- a/lib/bodyScrollLock.min.js +++ b/lib/bodyScrollLock.min.js @@ -1 +1 @@ -!function(e,o){if("function"==typeof define&&define.amd)define(["exports"],o);else if("undefined"!=typeof exports)o(exports);else{var t={};o(t),e.bodyScrollLock=t}}(this,function(exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=!1;if("undefined"!=typeof window){var e={get passive(){t=!0}};window.addEventListener("testPassive",null,e),window.removeEventListener("testPassive",null,e)}function d(o){return s.some(function(e){return!(!e.options.allowTouchMove||!e.options.allowTouchMove(o))})}function l(e){var o=e||window.event;return!!d(o.target)||(1 { const scrollBarGap = window.innerWidth - document.documentElement.clientWidth; if (reserveScrollBarGap && scrollBarGap > 0) { - const computedBodyPaddingRight = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'), 10); - previousBodyPaddingRight = document.body.style.paddingRight; - document.body.style.paddingRight = `${computedBodyPaddingRight + scrollBarGap}px`; + const computedBodyPaddingRight = parseInt(window.getComputedStyle(window.top.document.body).getPropertyValue('padding-right'), 10); + previousBodyPaddingRight = window.top.document.body.style.paddingRight; + window.top.document.body.style.paddingRight = `${computedBodyPaddingRight + scrollBarGap}px`; } } // If previousBodyOverflowSetting is already set, don't set it again. if (previousBodyOverflowSetting === undefined) { - previousBodyOverflowSetting = document.body.style.overflow; - document.body.style.overflow = 'hidden'; + previousBodyOverflowSetting = window.top.document.body.style.overflow; + window.top.document.body.style.overflow = 'hidden'; } }; const restoreOverflowSetting = () => { if (previousBodyPaddingRight !== undefined) { - document.body.style.paddingRight = previousBodyPaddingRight; + window.top.document.body.style.paddingRight = previousBodyPaddingRight; // Restore previousBodyPaddingRight to undefined so setOverflowHidden knows it // can be set again. @@ -99,7 +99,7 @@ const restoreOverflowSetting = () => { } if (previousBodyOverflowSetting !== undefined) { - document.body.style.overflow = previousBodyOverflowSetting; + window.top.document.body.style.overflow = previousBodyOverflowSetting; // Restore previousBodyOverflowSetting to undefined // so setOverflowHidden knows it can be set again. @@ -111,38 +111,29 @@ const setPositionFixed = () => window.requestAnimationFrame(() => { // If previousBodyPosition is already set, don't set it again. if (previousBodyPosition === undefined) { previousBodyPosition = { - position: document.body.style.position, - top: document.body.style.top, - left: document.body.style.left + position: window.top.document.body.style.position, + top: window.top.document.body.style.top, + left: window.top.document.body.style.left }; // Update the dom inside an animation frame const { scrollY, scrollX, innerHeight } = window; - document.body.style.position = 'fixed'; - document.body.style.top = `${-scrollY}px`; - document.body.style.left = `${-scrollX}px`; - - setTimeout(() => window.requestAnimationFrame(() => { - // Attempt to check if the bottom bar appeared due to the position change - const bottomBarHeight = innerHeight - window.innerHeight; - if (bottomBarHeight && scrollY >= innerHeight) { - // Move the content further up so that the bottom bar doesn't hide it - document.body.style.top = -(scrollY + bottomBarHeight); - } - }), 300) + window.top.document.body.style.position = 'fixed'; + window.top.document.body.style.top = `${-scrollY}px`; + window.top.document.body.style.left = `${-scrollX}px`; } }); const restorePositionSetting = () => { if (previousBodyPosition !== undefined) { // Convert the position from "px" to Int - const y = -parseInt(document.body.style.top, 10); - const x = -parseInt(document.body.style.left, 10); + const y = -parseInt(window.top.document.body.style.top, 10); + const x = -parseInt(window.top.document.body.style.left, 10); // Restore styles - document.body.style.position = previousBodyPosition.position; - document.body.style.top = previousBodyPosition.top; - document.body.style.left = previousBodyPosition.left; + window.top.document.body.style.position = previousBodyPosition.position; + window.top.document.body.style.top = previousBodyPosition.top; + window.top.document.body.style.left = previousBodyPosition.left; // Restore scroll window.scrollTo(x, y);