Posted By

phiqle on 02/12/12


Tagged

jquery Textpander


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

spee66
BrockSamsom
Priestd09


jQuery Textpander


 / Published in: jQuery
 

Simple jQuery Textpander

  1. <html>
  2. <head>
  3. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  4.  
  5. <style type="text/css">
  6.  
  7. .container_12 {
  8. margin: 0 auto;
  9. width: 960px;
  10. }
  11.  
  12. .grid_6 {
  13. width: 420px;
  14. }
  15.  
  16. #textpanda {
  17. background-color:#ffcccc;
  18. }
  19.  
  20. .headline {
  21. background-color: #000000;
  22. border: 0 0 1px 0 solid #fff;
  23. color: #ffffff;
  24. cursor: pointer;
  25. font-family: georgia;
  26. margin-top: -14px;
  27. padding: 10px;
  28. }
  29.  
  30. .headline:before {
  31. color: #ffffff;
  32. content: "+ ";
  33. }
  34.  
  35. h3.headline {
  36. margin: 0;
  37. }
  38.  
  39. h3.headline:hover {
  40. background-color: #ff0000;
  41. }
  42.  
  43. .expanded:before {
  44. content: "- ";
  45. padding-right: 6px;
  46. }
  47.  
  48. .content {
  49. background-color:#ffcccc;
  50. padding: 20px;
  51. }
  52. </style>
  53.  
  54. </head>
  55. <body>
  56. <div class="container_12">
  57. <div id="textpanda" class="grid_6">
  58. <h3 class="headline">ONE </h3>
  59. <p class="content">
  60. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur?
  61. </p>
  62.  
  63. <h3 class="headline">TWO </h3>
  64. <p class="content">
  65. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
  66. </p>
  67.  
  68. <h3 class="headline">THREE </h3>
  69. <p class="content">
  70. Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
  71. </p>
  72. </div>
  73. </div>
  74. </body>
  75. </style>
  76. <script type="text/javascript">
  77. $(document).ready(function() {
  78.  
  79. var $textpanderContent = $(".content");
  80. var $headine = $(".headline")
  81.  
  82. $textpanderContent.hide();
  83. $headine.click(function() {
  84.  
  85. var $headlineThis = $(this);
  86.  
  87. $headlineThis.next($textpanderContent).slideToggle("fast", function(){
  88. if ($headlineThis.css("display") == "block") {
  89. $headlineThis.prev().addClass("expanded");
  90. }
  91. else {
  92. $headlineThis.prev().removeClass("expanded");
  93. }
  94. });
  95. });
  96. });
  97. </script>
  98. </html>

Report this snippet  

You need to login to post a comment.