body-scroll-freezer
Advanced tools
Comparing version 1.0.1 to 1.0.2
/** | ||
* body-scroll-freezer - Dependency-free JS module to freeze body scroll when opening modal box | ||
* | ||
* @version v1.0.0 | ||
* @version v1.0.2 | ||
* @link https://github.com/ramonvictor/body-scroll-freezer/ | ||
@@ -9,2 +9,2 @@ * @author @ramonvictor | ||
*/ | ||
!function(){"use strict";function e(){return this.scrollWidth=l=i()}function t(){c.style.overflow="hidden",l&&(d()&&(c.style.paddingRight=l+"px"),p&&o())}function n(){c.style.overflow="",l&&(c.style.paddingRight="",p&&o())}function i(){var e,t=document.createElement("div");return t.className=u,c.appendChild(t),e=t.offsetWidth-t.clientWidth,c.removeChild(t),e}function d(){return c.scrollHeight>document.documentElement.clientHeight}function o(){f=f===!0?!1:!0,f?window.addEventListener("resize",r,!1):window.removeEventListener("resize",r,!1)}function r(){d()?c.style.paddingRight=l+"px":c.style.paddingRight=""}var l,s={},u="js-scrollbar-measure",c=document.body,f=!1,p="addEventListener"in Element.prototype;s.init=e,s.freeze=t,s.unfreeze=n,"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=s:"undefined"!=typeof window&&(window.bodyScrollFreezer=s)}(); | ||
!function(){"use strict";function e(){return this.scrollWidth=l=i()}function t(){c.style.overflow="hidden",l&&(o()&&(c.style.paddingRight=l+"px"),p&&d())}function n(){c.style.overflow="",l&&(c.style.paddingRight="",p&&d())}function i(){var e,t=document.createElement("div");return t.className=s,c.appendChild(t),e=t.offsetWidth-t.clientWidth,c.removeChild(t),e}function o(){return c.scrollHeight>document.documentElement.clientHeight}function d(){f=f===!0?!1:!0,f?window.addEventListener("resize",r,!1):window.removeEventListener("resize",r,!1)}function r(){m||(o()?c.style.paddingRight=l+"px":c.style.paddingRight="",m=!0,window.setTimeout(function(){m=!1},150))}var l,u={},s="js-scrollbar-measure",c=document.body,f=!1,m=!1,p="addEventListener"in Element.prototype;u.init=e,u.freeze=t,u.unfreeze=n,"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=u:"undefined"!=typeof window&&(window.bodyScrollFreezer=u)}(); |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"main": "docs/js/body-scroll-freezer.min.js", | ||
@@ -9,0 +9,0 @@ "homepage": "https://github.com/ramonvictor/body-scroll-freezer/", |
@@ -12,2 +12,3 @@ (function() { | ||
var isFroozen = false; | ||
var resizeWait = false; | ||
var supportsEventListener = ('addEventListener' in Element.prototype); | ||
@@ -110,2 +111,6 @@ | ||
function onWindowResize() { | ||
if (resizeWait) { | ||
return; | ||
} | ||
if (windowHasScroll()) { | ||
@@ -116,2 +121,5 @@ body.style.paddingRight = scrollWidth + 'px'; | ||
} | ||
resizeWait = true; | ||
window.setTimeout(function() { resizeWait = false; }, 150); | ||
} | ||
@@ -118,0 +126,0 @@ |
28523
175