5

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 :)

Jezthomp
  • 709
  • 5
  • 11
  • 16
  • 2
    Why you don't try to follow the tutorial you linked and change toggle() by slideToggle()? – Miquel Jan 13 '12 at 11:30

3 Answers3

5

It's simple, yet effective.

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

  $("p").slideToggle();
});
Syntactic Fructose
  • 18,936
  • 23
  • 91
  • 177
Christopher
  • 431
  • 2
  • 6
  • 13
1

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();
}); 
Lubor Bílek
  • 322
  • 1
  • 9
  • Thanks guys, i need the 'read more' to change to 'read less' i have found some examples of click slide up and down but need that to change really. – Jezthomp Jan 13 '12 at 13:24
0

you could use jquery's built in functions to .slide() or animate()

so instead of using:

$('#someElement').html('some content');

try

$('#someElement').html('some content').slideDown(some speed ie 600);

you'd need to hide (ie display:none) the content area first. maybe wrap the content in a div with a id/class and set that to display:none

atmd
  • 7,430
  • 2
  • 33
  • 64