Last active
August 23, 2019 03:20
-
-
Save jondavidjohn/4567050 to your computer and use it in GitHub Desktop.
Animate any node to a new parent
This file contains 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
/* | |
Animate any Node to a new parent node, retaining original object reference | |
Derived From : http://stackoverflow.com/a/5212193/555384 | |
*/ | |
function moveAnimate($element, $newParent){ | |
var oldOffset, newOffset, $temp; | |
$element = $($element); //Allow passing in either a JQuery object or selector | |
$newParent= $($newParent); //Allow passing in either a JQuery object or selector | |
oldOffset = $element.offset(); | |
$element.appendTo($newParent); | |
newOffset = $element.offset(); | |
$temp = $element.clone().appendTo('body'); | |
$temp.css('position', 'absolute') | |
.css('left', oldOffset.left) | |
.css('top', oldOffset.top) | |
.css('zIndex', 1000); | |
$element.hide(); | |
$temp.animate( {'top': newOffset.top, 'left':newOffset.left}, 'slow', function(){ | |
$element.show(); | |
$temp.remove(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment