Skip to content

Instantly share code, notes, and snippets.

@rtt
Created April 9, 2013 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtt/5344364 to your computer and use it in GitHub Desktop.
Save rtt/5344364 to your computer and use it in GitHub Desktop.
$.fn.slideTo = function(data) {
var width = parseInt($('#slider').css('width'));
var transfer = $('<div class="transfer"></div>').css({ 'width': (2 * width) + 'px' });
var current = $('<div class="current"></div>').css({ 'width': width + 'px', 'left': '0', 'float': 'left' }).html($('#slider').html());
var next = $('<div class="next"></div>').css({ 'width': width + 'px', 'left': width + 'px', 'float': 'left' }).html(data);
transfer.append(current).append(next);
$('#slider').html('').append(transfer);
transfer.animate({ 'margin-left': '-' + width + 'px' }, 300, function () {
$('#slider').html(data);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment