@sect/100vh
Version:
Lightweight JS package for easy overcoming the problem with 100vh on mobile devices
2 lines (1 loc) • 2.31 kB
JavaScript
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).vh=n()}(this,function(){var e=/iPhone/i,n=/iPod/i,i=/iPad/i,t=/\biOS-universal(?:.+)Mac\b/i,o=/\bAndroid(?:.+)Mobile\b/i,r=/Android/i,a=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,d=/Silk/i,u=/Windows Phone/i,p=/\bWindows(?:.+)ARM\b/i,c=/BlackBerry/i,l=/BB10/i,s=/Opera Mini/i,f=/\b(CriOS|Chrome)(?:.+)Mobile/i,b=/Mobile(?:.+)Firefox\b/i,h=function(e){return void 0!==e&&"MacIntel"===e.platform&&"number"==typeof e.maxTouchPoints&&e.maxTouchPoints>1&&"undefined"==typeof MSStream};function v(v){var m={userAgent:"",platform:"",maxTouchPoints:0};v||"undefined"==typeof navigator?"string"==typeof v?m.userAgent=v:v&&v.userAgent&&(m={userAgent:v.userAgent,platform:v.platform,maxTouchPoints:v.maxTouchPoints||0}):m={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0};var w=m.userAgent,y=w.split("[FBAN");void 0!==y[1]&&(w=y[0]),void 0!==(y=w.split("Twitter"))[1]&&(w=y[0]);var g=function(e){return function(n){return n.test(e)}}(w),A={apple:{phone:g(e)&&!g(u),ipod:g(n),tablet:!g(e)&&(g(i)||h(m))&&!g(u),universal:g(t),device:(g(e)||g(n)||g(i)||g(t)||h(m))&&!g(u)},amazon:{phone:g(a),tablet:!g(a)&&g(d),device:g(a)||g(d)},android:{phone:!g(u)&&g(a)||!g(u)&&g(o),tablet:!g(u)&&!g(a)&&!g(o)&&(g(d)||g(r)),device:!g(u)&&(g(a)||g(d)||g(o)||g(r))||g(/\bokhttp\b/i)},windows:{phone:g(u),tablet:g(p),device:g(u)||g(p)},other:{blackberry:g(c),blackberry10:g(l),opera:g(s),firefox:g(b),chrome:g(f),device:g(c)||g(l)||g(s)||g(b)||g(f)},any:!1,phone:!1,tablet:!1};return A.any=A.apple.device||A.android.device||A.windows.device||A.other.device,A.phone=A.apple.phone||A.android.phone||A.windows.phone,A.tablet=A.apple.tablet||A.android.tablet||A.windows.tablet,A}var m=function(e){document.documentElement.style.setProperty("--vh",e+"px"),window.vh=e},w=function(e,n,i){requestAnimationFrame(function(){var t=i&&"orientationchange"===i.type,o=i&&"resize"===i.type;m(n),(!v().any||t||void 0===t)&&m(t?e:n),v().any&&!o&&void 0!==o||m(n)})};return{init:function(){!function(e){function n(n){return e(window.innerWidth,window.innerHeight,n)}window.addEventListener("resize",n),window.addEventListener("orientationchange",n),n(e)}(w)}}});