Jquery UI è fantastico, ma è un sacco di cose extra solo per una piccola fisarmonica. Se hai intenzione di utilizzare tutte le funzionalità, allora fallo.
È anche possibile utilizzare i metodi jQuery show(), nascondere() o attivare(). Segui i link per saperne di questi, non li spiegherò qui.
Il problema con tutti questi è mostrare o nascondere TUTTO il testo, come dimostrano alcune delle altre risposte qui. Se si desidera mostrare una o due righe (o dieci) del testo attuale, quindi visualizzarlo tutto facendo clic su un pulsante/collegamento, è necessario un po 'più dei metodi predefiniti. Se vuoi solo un piccolo script per farlo, o vuoi solo capire come è fatto, ecco il mio piccolo plugin. Il mio script anima l'apertura e la chiusura della fisarmonica simile a show()/hide(), ma mostrerà una quantità predefinita di testo nella posizione chiusa.
Fiddle
Spero che questo aiuti
HTML
<div class="show-more-snippet">
//your text goes here//
</div>
<a href="#" class="show-more">More...</a>
CSS
.show-more-snippet {
height:35px; /*this is set to the height of the how much text you want to show based on the font size, line height, etc*/
width:300px;
overflow:hidden;
}
jQuery
$('.show-more').click(function() {
if($('.show-more-snippet').css('height') != '35px'){
$('.show-more-snippet').stop().animate({height: '35px'}, 200);
$(this).text('More...');
}else{
$('.show-more-snippet').css({height:'100%'});
var xx = $('.show-more-snippet').height();
$('.show-more-snippet').css({height:'35px'});
$('.show-more-snippet').stop().animate({height: xx}, 400);
// ^^ The above is beacuse you can't animate css to 100%. So I change it to 100%, get the value, change it back, then animate it to the value. If you don't want animation, you can ditch all of it and just leave: $('.show-more-snippet').css({height:'100%'});^^ //
$(this).text('Less...');
}
});
Se la mia risposta l'ha aiutata, per favore accettala. –