If you can catch the "ad loaded" event and add a class to your div accordingly you can try setting the max-height
of the div instead of height.
function addElement() {
var initialDiv = document.getElementsByClassName('yourDiv')[0];
var newdiv = document.createElement('div');
newdiv.setAttribute('style','height: 300px;');
initialDiv.classList.add('loaded');
newdiv.innerHTML = '<img src="http://placehold.it/300x300"/>';
initialDiv.appendChild(newdiv);
}
setTimeout(function(){
addElement();
}, 1000);
.yourDiv {
min-height: 90px;
width: 300px;
background-color: grey;
max-height: 90px;
transition: max-height 500ms ease-in;
overflow: hidden;
}
.yourDiv.loaded {
max-height: 300px;
transition: max-height 500ms ease-in;
}
<div class="yourDiv">
</div>
You can set the max-height to 300px or more, it doesn't really matter.
EDIT:
Based on your comment. There actually is an event you can listen to in GPT. You can simply add it when pushing the ads like this:
googletag.pubads().addEventListener('slotRenderEnded', function(event) {
// slot has been rendered - do stuff
});
Now I'm not sure how you've done yours but I think you can implement this easily to your existing code.
A working example: https://jsfiddle.net/thepio/7tfdxw8f/