Skip to content

Instantly share code, notes, and snippets.

@benshimmin
Last active December 12, 2015 09:19
Show Gist options
  • Save benshimmin/4751008 to your computer and use it in GitHub Desktop.
Save benshimmin/4751008 to your computer and use it in GitHub Desktop.
Moving Raphaël elements up and down the stack, one by one
shift = (element, dir) ->
if dir is "down"
fn = "insertBefore"
prop = "prev"
else
fn = "insertAfter"
prop = "next"
# sibling (either next or previous)
sib = element[prop]
# you might also want to check the type of `sib` here
while sib then sib = sib[prop]
# call `insertBefore/After` on element in relation to
# its sibling
if sib then element[fn] sib
# usage:
shift myElement, "up"
shift myElement, "down"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment