Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Read More/Less Slide Toggle?

I'm after a simple slide toggle for a read more link then when expanded a read less link.

Exactly like this but needs to slide down rather than just appear like that.

The initial height needs to be set as well whether through words or box height.

Any ideas, is it fairly simple to achieve?

Thanks for any help :)

like image 773
Jezthomp Avatar asked Jan 13 '12 11:01

Jezthomp


2 Answers

It's simple, yet effective.

$(".button").click(function(){
  var moreAndLess = $("p").is(':visible') ? 'More' : 'Less';
  $(this).text(moreAndLess);

  $("p").slideToggle();
});
like image 123
Christopher Avatar answered Sep 30 '22 12:09

Christopher


The example you mentioned use toggle() function, which just shows or hides the element (display: block / hidden) without any effect.

You have to use slideToggle() function, which does the same thing, but with sliding effect.

$("button").click(function(){
  $("p").slideToggle();
}); 
like image 35
Lubor Bílek Avatar answered Sep 30 '22 14:09

Lubor Bílek