It sounds like such a easy task but I am finding this very hard to get this working correctly due to images loading after the script and hidden children. I keep getting different heights each time I load the page.
$("h2").click(function(){
var $wrap = $(this).parents(".wrapper");
$wrap.find(".scroller").height(function(){
var height = 0;
$wrap.find(".scroller > li:lt(3)").each(function(){
height += $(this).outerHeight(true);
});
return height;
}).slideDown();
});
$("h2").eq(0).click();
Not very elegant, but this should be a sturdy solution for setting the scroller’s height to the height of its first 3
liitems:Fiddle
I’ve edited your fiddle slightly to give different sizes to the images for better testing.
I tried making a solution with
.position()but it gave weird results, sodetachthelis > 2, get the.scroller‘souterHeightwith solely the first 3lis and reattach the detachedlis is the best solution I can imagine.