body-scroll-freezer
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -9,2 +9,2 @@ /** | ||
*/ | ||
!function(){"use strict";function e(){return this.scrollWidth=l=i()}function t(){s.style.overflow="hidden",l&&(o()&&(s.style.paddingRight=l+"px"),c&&d(!0))}function n(){s.style.overflow="",l&&(s.style.paddingRight="",c&&d(!1))}function i(){var e,t=document.createElement("div");return t.setAttribute("style",p),s.appendChild(t),e=t.offsetWidth-t.clientWidth,s.removeChild(t),e}function o(){return s.scrollHeight>document.documentElement.clientHeight}function d(e){e?window.addEventListener("resize",r,!1):window.removeEventListener("resize",r,!1)}function r(){f||(o()?s.style.paddingRight=l+"px":s.style.paddingRight="",f=!0,window.setTimeout(function(){f=!1},150))}var l,u={},s=document.body,f=!1,c="addEventListener"in Element.prototype,p=["width: 100px","height: 100px","overflow: scroll","position: absolute","top: -9999px"].join(";");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)}(); | ||
!function(){"use strict";function e(){return"undefined"!=typeof l?l:this.scrollWidth=l=i()}function t(){s.style.overflow="hidden",l&&(o()&&(s.style.paddingRight=l+"px"),c&&d(!0))}function n(){s.style.overflow="",l&&(s.style.paddingRight="",c&&d(!1))}function i(){var e,t=document.createElement("div");return t.setAttribute("style",["width: 100px","height: 100px","overflow: scroll","position: absolute","top: -9999px"].join(";")),s.appendChild(t),e=t.offsetWidth-t.clientWidth,s.removeChild(t),e}function o(){return s.scrollHeight>document.documentElement.clientHeight}function d(e){e?window.addEventListener("resize",r,!1):window.removeEventListener("resize",r,!1)}function r(){f||(o()?s.style.paddingRight=l+"px":s.style.paddingRight="",f=!0,window.setTimeout(function(){f=!1},150))}var l,u={},s=document.body,f=!1,c="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.4", | ||
"version": "1.0.5", | ||
"main": "docs/js/body-scroll-freezer.min.js", | ||
@@ -9,0 +9,0 @@ "homepage": "https://github.com/ramonvictor/body-scroll-freezer/", |
@@ -12,11 +12,3 @@ (function() { | ||
var supportsEventListener = ('addEventListener' in Element.prototype); | ||
var measureScrollStyle = [ | ||
'width: 100px', | ||
'height: 100px', | ||
'overflow: scroll', | ||
'position: absolute', | ||
'top: -9999px' | ||
].join(';'); | ||
/** | ||
@@ -29,2 +21,5 @@ * Init module by getting browser scroll width. | ||
/* jshint validthis:true */ | ||
if (typeof scrollWidth !== 'undefined') { | ||
return scrollWidth; | ||
} | ||
return (this.scrollWidth = scrollWidth = getScrollWidth()); | ||
@@ -72,3 +67,3 @@ } | ||
/** | ||
* Append/remove `div.js-scrollbar-measure` just to measure scroll bar width. | ||
* Append/remove `<div>` to measure browser's scrollbar width. | ||
* Props to {@link https://davidwalsh.name/detect-scrollbar-width|@davidwalshblog}. | ||
@@ -82,5 +77,11 @@ * @private | ||
div.setAttribute('style', measureScrollStyle); | ||
div.setAttribute('style', [ | ||
'width: 100px', | ||
'height: 100px', | ||
'overflow: scroll', | ||
'position: absolute', | ||
'top: -9999px' | ||
].join(';')); | ||
body.appendChild(div); | ||
scrollBarWidth = div.offsetWidth - div.clientWidth; | ||
@@ -87,0 +88,0 @@ body.removeChild(div); |
Sorry, the diff of this file is not supported yet
28828
9
196