Is there a way to run some code every time the web page height
is changed via JavaScript? (The web page height
itself, not the browser height.) I would prefer not to use jQuery if at all possible. If that's not possible, would there be another way to accomplish the following?
I am animating the height
change of a div
located at the bottom of the page, triggered by the user clicking a button. I want the page to remain scrolled to the bottom of the page while this is occurring. I figured I could listen for a height
change event and update the scroll position each time, then it would be smooth. My current approach is to wait until the animation is completed and then scroll to the bottom, but this has no animation effects and is obviously delayed until after the entire height
is updated.
Current code:
JS:
var myDiv = document.querySelector("#myDiv");
var activeClass = "activeDiv";
if (myDiv.className == activeClass) {
myDiv.className = "";
}
else {
myDiv.className = activeClass;
setTimeout("window.scrollTo(0,document.body.scrollHeight)", 150);
}
CSS:
#myDiv {
max-height: 0;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.activeDiv {
max-height: 500px !important;
}