views:

68

answers:

1

I'm trying to write some javascript that will stack objects by setting z-index.

Test Case: http://christophermeyers.name/stacker/

I've hacked that together, but I'd like to extrapolate that behavior to something a little more logical. That is:

Given x number of elements, when element C is moved to the top, all elements above that element must move down 1, while all elements below that element should remain in place.

A: 

A "linked list" makes for a good data structure when you're doing this kind of thing. Keep track of the order of your stackable elements via a series of simple nodes..

// ListNode
{
    value: {}
    next: {<ListNode>}
}

..and update the sequence as new nodes are added or selected.

I have posted a working example of a list being used for depth sorting at the following URL:

http://aethermedia.net/sandbox/depth-sorting.html

Sorry I don't have time to pull up a more appropriate tutorial =/

cdata