Created
September 24, 2016 14:29
-
-
Save JoeSz/e7028d6738bb1633d792cd127dc2115e to your computer and use it in GitHub Desktop.
Detect Element Height Change (eg. Window)
This file contains 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
// Source: http://stackoverflow.com/questions/14866775/detect-document-height-change | |
var $j = jQuery.noConflict(); | |
$j( document ).ready(function($) { | |
function onElementHeightChange(elm, callback){ | |
var lastHeight = elm.clientHeight, newHeight; | |
(function run(){ | |
newHeight = elm.clientHeight; | |
if( lastHeight != newHeight ) | |
callback(); | |
lastHeight = newHeight; | |
if( elm.onElementHeightChangeTimer ) | |
clearTimeout(elm.onElementHeightChangeTimer); | |
elm.onElementHeightChangeTimer = setTimeout(run, 200); | |
})(); | |
} | |
onElementHeightChange(document.body, function(){ | |
console.log("height changed"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment