UNPKG

carbon-components-angular

Version:
46 lines (43 loc) 1.56 kB
/*! * * Neutrino v0.0.0 | window-tools.js * * Copyright 2014, 2018 IBM * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var _scrollbarWidth = -1; export function getScrollbarWidth() { // lets not recreate this whole thing every time if (_scrollbarWidth >= 0) { return _scrollbarWidth; } // do the calculations the first time var outer = document.createElement("div"); outer.style.visibility = "hidden"; outer.style.width = "100px"; outer.style.msOverflowStyle = "scrollbar"; // needed for WinJS apps document.body.appendChild(outer); var widthNoScroll = outer.offsetWidth; // force scrollbars outer.style.overflow = "scroll"; // add innerdiv var inner = document.createElement("div"); inner.style.width = "100%"; outer.appendChild(inner); var widthWithScroll = inner.offsetWidth; // remove divs outer.parentNode.removeChild(outer); _scrollbarWidth = widthNoScroll - widthWithScroll; return _scrollbarWidth; } //# sourceMappingURL=window-tools.js.map