Created
December 14, 2010 20:16
-
-
Save emperorcezar/741018 to your computer and use it in GitHub Desktop.
This is a small jquery plugin that allows a div that partially collapses
This file contains 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
(function( $ ){ | |
$.fn.pCollapse = function( options ) { | |
var settings = { | |
'start': '100px', | |
}; | |
// there's no need to do $(this) because | |
// "this" is already a jquery object | |
// $(this) would be the same as $($('#element')); | |
return this.each(function() { | |
// If options exist, lets merge them | |
// with our default settings | |
if ( options ) { | |
$.extend( settings, options ); | |
} | |
var $this = $(this); | |
$this.attr('full-height', $this.height()); | |
var after = $this.after('<div><a href="#">More</a></div>').next(); | |
$(after).click(function(){ | |
if ( $this.height() == $this.attr('full-height') ){ | |
// Collapse | |
$this.animate({height:settings.start}); | |
$('a', after).html('More'); | |
} else { | |
$this.animate({height:$this.attr('full-height') + 'px'}); | |
$('a', after).html('Less'); | |
} | |
}); | |
$this.css('height', settings.start); | |
$this.css('overflow', 'hidden'); | |
}); | |
}; | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment