...

Prototype: get all childElements with <img> & combine their height for 1 value

rhinodog8
11-20-2008, 09:26 AM
I don't really know where to start even in theory, but I know there is a way. Could someone point me into the right direction?

ohgod
11-21-2008, 03:55 PM
$$('img') would pull all img tags

http://www.prototypejs.org/api/utility/dollar-dollar

suffix it with an each statement to walk through and get all the values:

http://www.prototypejs.org/api/array/each

and use getHeight to get the height and add them up...

http://www.prototypejs.org/api/element/getheight

function(){

var total = 0;

$$('img').each(function(s){ elval = s.getHeight();
total = total + elval;
})

return total;
}

play around with it, i'm sure i made a couple dumb mistakes and it's untested. anyone else feel free to double check that for retardation.

rhinodog8
11-29-2008, 01:32 AM
Wow, thanks so much. Your code worked right out of the box. But i modified it a little for an each function inside a specific div containing imgs and to include the offset width of the imgs.

also eval threw an error, although it got the heights, so I just used s as the variable.

Heres what my code if anyone was wandering...
total=0;
//search picture li for first div's images and combines all the widths of each image

b.childElements()[0].select('img').each(function (w) {s=w.offsetWidth;total= total+s;});

//Set the inner pcture div to all the images combined width & plus 3 for IE6

b.childElements()[0].setStyle({width: total+3+'px'});



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum