Skip to content

Instantly share code, notes, and snippets.

@willcalderbank
Created April 28, 2015 11:01
Show Gist options
  • Save willcalderbank/b997568b61662853ce71 to your computer and use it in GitHub Desktop.
Save willcalderbank/b997568b61662853ce71 to your computer and use it in GitHub Desktop.
switchSrc
switchSrc: function(overlayId, src, duration) {
var $original = $('#' + overlayId);
$newElement = $original.clone();
$newElement.removeAttr('id');
$newElement.css({opacity: 0, background: 'url(' + src + ')'});
$original.after($newElement);
if (duration === undefined) {
duration = 200;
}
$newElement.velocity({opacity: 1}, {duration: duration, complete: function() {
$original.css('background', 'url(' + src + ')');
$newElement.remove();
}});
},
@willcalderbank
Copy link
Author

Switches divs background with a smooth transition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment