javascript - Alternative to setTimeout for images -


if want create div high (responsive) image using javascript, resorting settimeout. example might have code this

settimeout(function(){     var $imgheight = $('img').height();     $('.mydiv').height($imgheight); }, 400); 

is there alternative this? know imagesloaded plugin, there simpler alternative?

many thanks

you can use load event know when images loaded:

$('img').on('load', function(){     $('.mydiv').height(this.height); }); 

http://jsfiddle.net/083d89me/

though don't see need set divs height. doesn't adjust image height default?


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -