Reputation: 193
I was wondering if there's a jQuery function that do the same effect as this code without using jQuery UI?
$(selector).show('slide', { direction: 'right' }, 300);
Upvotes: 2
Views: 2240
Reputation: 41533
Here's a quick plugin that I came up with. It basically animates the width
and opacity
properties:
$.fn.slideRight = function(duration, callback) {
duration = duration || 300;
return this.each(function() {
var $this = $(this),
css = getInitialStyle($this);
$this
.css({width: 0, display: 'block'})
.animate(css, duration, callback);
});
function getInitialStyle($el){
var css = $el.data('initialStyle');
if(!css || !css.width || !css.opacity) {
var isHidden = $el.is(':hidden');
if(isHidden) $el.show();
css = {
width: $el.width(),
opacity: $el.css('opacity')
}
if(isHidden) $el.hide();
$el.data('initialStyle', css);
}
return css;
}
}
And here's the live demo.
Upvotes: 0