Last active
March 7, 2017 22:35
-
-
Save darcyclarke/e582dd262e5c6d366b5747a5b944c6f3 to your computer and use it in GitHub Desktop.
jQuery plugin for animating elements with floats
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
/*! | |
* Animate Floats jQuery Plugin | |
* http://darcyclarke.me/articles/development/animate-float-positions-in-jquery-1-5/ | |
* | |
* Copyright 2016, Darcy Clarke | |
* Do what you want license | |
*/ | |
(function(window, $){ | |
var $plugin = $.sub(); | |
$plugin.fn.animate = function(props, speed, cb){ | |
if(typeof(speed) == 'function') | |
cb = speed, speed = 500; | |
if(typeof(cb) != 'function') | |
cb = function(){}; | |
return $.each(this, function(i, el){ | |
el = $(el); | |
if(props.float && props.float != el.css('float')){ | |
var elem = el.clone().css(props).insertBefore(el), | |
temp = (props.float == el.css('float')) ? elem.position().left : el.position().left; | |
props.marginLeft = elem.position().left; | |
elem.remove(); | |
el.css({float:'left',marginLeft:temp}); | |
} | |
$(this).animate(props, speed, function(){ | |
$(this).css(props); | |
cb(); | |
}); | |
}); | |
}; | |
window.$ = $plugin; | |
})(window, jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment