Skip to content

Instantly share code, notes, and snippets.

@visualmotive
Created June 7, 2011 18:40
Show Gist options
  • Save visualmotive/1012852 to your computer and use it in GitHub Desktop.
Save visualmotive/1012852 to your computer and use it in GitHub Desktop.
(function($) {
$.fn.slide = function strength(options) {
var defaults = {
'direction': 'left', // can also be 'right'
'duration': 500,
'callback': function() {}
};
if (options === 'left' || options === 'right') {
options = {'direction': options};
}
options = $.extend(defaults, options);
var $this = this,
frame = this.parent(),
width = frame.width(),
next = (options.direction == 'left' ? this.next() : this.prev()),
next_start = (options.direction == 'left' ? width : width * -1);
this_end = (options.direction == 'left' ? width * -1 : width);
if (!next.length) {
return this;
}
frame.css({
'overflow': 'hidden',
'width': width,
'display': 'block',
'position': 'relative'
});
this.css({
'position': 'absolute',
'top': 0,
'left': 0
});
next.css({
'position': 'absolute',
'top': 0,
'left': next_start
}).show();
frame.height(Math.max(this.outerHeight(true), next.outerHeight(true)));
this.stop().animate({'left': this_end}, options.duration, function() {
$this.hide();
frame.css({'overflow': 'visible'});
options.callback();
});
next.stop().show().animate({'left': 0}, options.duration, function() {
next.css({'position': 'relative'});
frame.animate({'height': next.outerHeight(true)}, function() {
frame.css({'height': 'auto'});
});
});
if (frame.offset().top < $(window).scrollTop()) {
$(window).scrollTo(frame, options.duration);
}
return this;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment