Last active
January 5, 2019 18:27
-
-
Save crazyyy/223825b936e90cd537a5 to your computer and use it in GitHub Desktop.
#js #jquery || get browser width and height on window resize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get browser width and height on window resize | |
var headerEl = document.getElementById('header'); | |
// when window size changed - resize first block | |
window.addEventListener('resize', setWindowSize); | |
function setWindowSize() { | |
if (typeof(window.innerWidth) == 'number') { | |
myWidth = window.innerWidth; | |
myHeight = window.innerHeight; | |
setheight(myHeight); | |
} else { | |
if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { | |
myWidth = document.documentElement.clientWidth; | |
myHeight = document.documentElement.clientHeight; | |
setheight(myHeight); | |
} else { | |
if (document.body && (document.body.clientWidth || document.body.clientHeight)) { | |
myWidth = document.body.clientWidth; | |
myHeight = document.body.clientHeight; | |
setheight(myHeight); | |
} | |
} | |
} | |
} | |
function setheight(height) { | |
headerEl.style.height = height + 'px'; | |
} | |
document.addEventListener("DOMContentLoaded", function(event) { | |
setWindowSize(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment