Skip to content

Instantly share code, notes, and snippets.

@jondavidjohn
Last active August 23, 2019 03:20
Show Gist options
  • Save jondavidjohn/4567050 to your computer and use it in GitHub Desktop.
Save jondavidjohn/4567050 to your computer and use it in GitHub Desktop.
Animate any node to a new parent
/*
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