Scott Yu - builds stuff
Scott Yu - builds stuff

Reputation: 11763

How to auto-resize container that has absolute positioned children elements

Is there a way to resize a container so it's always compressed to fit absolute positioned elements inside it?

I like to create a drawing canvas and resize it to fit whatever user drags into it. If user moves the element outside of current size frame, I like the frame to resize to include element.

Sort of like Adobe Fireworks' FIT CANVAS feature.

Here's what I have so far. I have figured how to find outer wrap of right and bottom. But how to get the LEFT and TOP to wrap tight and not have empty space?

http://jsfiddle.net/AJLe7/10/

Thanks!

Upvotes: 0

Views: 307

Answers (1)

brains911
brains911

Reputation: 1310

Off the top of my head I think you would have to loop through each child element and find four numbers...

You container width would be the largest offsetX minus smallest offsetX and the height would be the largest offsetY minus the smallest offsetY.

Upvotes: 1

Related Questions