Forked from stevenmg/jquery-parent-to-animate.js
Last active
January 6, 2018 07:02
-
-
Save Symmetronic/a52d6ff79900986e70b025817366875b to your computer and use it in GitHub Desktop.
Transition/Animate move to new parent - jQuery plugin
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
// Usage: | |
// $('.box').parentToAnimate($('.new-parent'), 200); | |
// $('.box').parentToAnimate($('.new-parent'), 'slow'); | |
// $('.box').parentToAnimate('.new-parent', 'slow'); | |
jQuery.fn.extend({ | |
// Modified and Updated by MLM | |
// Origin: Davy8 (http://stackoverflow.com/a/5212193/796832) | |
parentToAnimate: function(newParent, duration) { | |
duration = duration || 'slow'; | |
var $element = $(this); | |
newParent = $(newParent); // Allow passing in either a JQuery object or selector | |
var oldOffset = $element.offset(); | |
var oldWidth = $element.width(); | |
var oldHeight = $element.height(); | |
$(this).appendTo(newParent); | |
var newOffset = $element.offset(); | |
var newWidth = $element.width(); | |
var newHeight = $element.height(); | |
var temp = $element.clone().removeAttr('id').appendTo('body'); | |
temp.css({ | |
'position': 'absolute', | |
'left': oldOffset.left, | |
'top': oldOffset.top, | |
'width': oldWidth, | |
'height': oldHeight, | |
'zIndex': 1000 | |
}); | |
$element.hide(); | |
temp.animate({ | |
'top': newOffset.top, | |
'left': newOffset.left, | |
'width': newWidth, | |
'height': newHeight | |
}, duration, function() { | |
$element.show(); | |
temp.remove(); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To make the parent height change smoothly i added this ,
`