fe-essential-utils
Version:
Essential utils for front-end development
1 lines • 1.22 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.DOMUtils=void 0;var bodyElement=document&&document.getElementsByTagName("body")[0],scrollToTop=function(e){var t=e||window;t.scroll?t.scroll({left:0,top:0,behavior:"smooth"}):t.scrollTop=0},injectPortalContainer=function(e,t){var o=document.createElement("div");o.setAttribute("id",e),o.setAttribute("class",t);var n=document.getElementById(e);return n||document.body.appendChild(o)},isElementInViewport=function(e){var t=e.getBoundingClientRect(),o=document.documentElement;return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||o.clientHeight)&&t.right<=(window.innerWidth||o.clientWidth)},isElementOutOfViewport=function(e){var t=e.getBoundingClientRect(),o=Math.max(document.documentElement.clientHeight,window.innerHeight);return!(t.bottom<0||t.top-o>=0)},freezeBody=function(){bodyElement&&(bodyElement.style.overflow="hidden")},relaxBody=function(){bodyElement&&(bodyElement.style.overflow="")},DOMUtils={scrollToTop:scrollToTop,injectPortalContainer:injectPortalContainer,isElementInViewport:isElementInViewport,isElementOutOfViewport:isElementOutOfViewport,freezeBody:freezeBody,relaxBody:relaxBody};exports.DOMUtils=DOMUtils;