Last active
December 12, 2015 09:19
-
-
Save benshimmin/4751008 to your computer and use it in GitHub Desktop.
Moving Raphaël elements up and down the stack, one by one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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