javascript - Read actual values of the class inside a function with object parameter passed before -
i trying set height objects of class depending on conditions inside function returned load()
event.
i have several images asynchronously loaded cloned divs of 1 class. goal set height parameter of shortest image whole class.
the images in below snippet random -- there different photos different original heights.
var h = [25,20,30,60,80,22]; var = h.length; for( ; i-- ; ){ var oc = $('div.obj').eq(0).clone(); oc.appendto($('body')); var oi = $('div.obj').eq(-1).children('img'); oi.load(oiload(oi,h[i])).attr({'src':'http://www.hughes.co.uk/showimage.php?image=hot-hv7l1451p.jpg&max_width='+h[i]+'&max_height='+h[i]+'&'+math.rand}); } function oiload(oi,hgt){ return function(){ if(oi.height() > hgt){ $('div.obj').css({'height':hgt+'px'}); console.log($('div.obj').height()); } } }
div.obj { background: black; float: left; } div.obj img { height: 40px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="obj"><img></div>
the problem oiload
function seems not have actual value of .obj
class height , claims condition in reference object in time passed function.
for above example, .obj
should 20px
of height (no smaller values after one) @ end gets last 1 smaller original 40px
.
wiki
Comments
Post a Comment