Skip to content

Instantly share code, notes, and snippets.

@byrichardpowell
Created July 12, 2012 15:19
Show Gist options
  • Save byrichardpowell/3098821 to your computer and use it in GitHub Desktop.
Save byrichardpowell/3098821 to your computer and use it in GitHub Desktop.
$ Truncate
( function($, undefined) {
// Truncates a wrapper & provides a more link to show the content in full
$.fn.truncate = function( c ) {
return this.each( function() {
// Trucate, add class, add more link
var $wrapper = $(this).css( { 'height' : c.height, 'overflow' : 'hidden'} ).addClass('truncated').after('<span class="truncate-more">more</span>');
// Show/Hide content
$wrapper.next().on( 'tap click', function(e) {
( $wrapper.height() === c.height ) ? $wrapper.height('auto') : $wrapper.height( c.height ) ;
});
})
}
}($) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment