Page 1 of 1
Trouble Stacking Different-Sized Boxes
Posted: Fri Sep 15, 2006 10:36 pm
by NinjaBot
Hi there.
I'm trying to stack some boxes. My code works, but I'm having trouble fathoming how to make the height of each box in the stack 'unique' instead of set to "10";
Code: Select all
$margin = "10";
$top0 = "10";
$height0 = "10";
$height1 = "12";
$height1 = "20";
for ($i = 1; $i < 8; $i++){
$prev = ($i - 1);
$prevHeight = "height".$prev;
$prevTop = "top".$prev;
$shift = ($$prevTop + $$prevHeight + $margin);
${"top" . $i} = $shift;
${"height" . $i} = $$prevHeight;
}
I should get something like the following:
Code: Select all
$top0 = "10";
$height0 = "10";
$top1 = "30";
$height1 = "12";
$top2 = "52";
$height2 = "20";
I'd much appreciate some help to fix this. Thanks.
Posted: Fri Sep 15, 2006 11:07 pm
by feyd
I have no idea what you're asking.
Posted: Fri Sep 15, 2006 11:15 pm
by NinjaBot
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
[quote="feyd"]I have no idea what you're asking.[/quote]
Maybe a fully formatted example may help:
Code: Select all
<?
$margin = "3";
$top0 = "10";
$height0 = "130";
$height1 = "300";
$height2 = "200";
for ($i = 1; $i < 8; $i++){
$prev = ($i - 1);
$prevHeight = "height".$prev;
$prevTop = "top".$prev;
$shift = ($$prevTop + $$prevHeight + $margin);
${"top" . $i} = $shift;
${"height" . $i} = $$prevHeight;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<title>Boxes</title>
<style type="text/css">
div {position: absolute;border: solid 1px #666;}
</style>
</head>
<body>
<div style="top:<?=$top0;?>px;height:<?=$height0;?>px">
<div style="top:<?=$top1;?>px;height:<?=$height1;?>px">
<div style="top:<?=$top2;?>px;height:<?=$height2;?>px">
</body>
</html>
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Fri Sep 15, 2006 11:24 pm
by feyd
The logic you have copies the previous height setting to the current height. I believe losing the last line of the loop will correct this problem.
Posted: Fri Sep 15, 2006 11:27 pm
by NinjaBot
feyd wrote:The logic you have copies the previous height setting to the current height. I believe losing the last line of the loop will correct this problem.
Thanks, feyd.
Indeed that was the problem. Can't believe I overlooked that.