I have tabs logic that load html templates inside a wrapper. That's works fine, but I included an animation that animate height
of the tab wrapper when tab is switched.
The problem is the following: When a template contains <img src="/some-image.png">
the $('#tab-content').load('template-url', function() {...})
callback function sometimes is executed before the browser show the images. And my animation is not working correctly.
var currentHeight = $contentHolder.height();
$contentHolder.load(path, function() {
$contentHolder.stop();
function animateHeight() {
var loadedContentHeight = $contentHolder.css('height', 'auto').height();
$contentHolder.height(currentHeight);
$contentHolder.animate({
height: loadedContentHeight
}, 800, 'linear');
}
animateHeight();
});
I tried to set little timeout, but it's not working every time. If I set more that 300ms timeout, It feels like tabs are changed too slow.
I tried to execute the animation when $('img').load(function() {})
is fired, but with no luck.
This bug occurs most often when the web page is fully refreshed and each tab content loading for first time.