Sfoglia il codice sorgente

Listing 4.11: toggling visibility.

Frederic G. MARAND 8 anni fa
parent
commit
e51759bf0c
1 ha cambiato i file con 9 aggiunte e 3 eliminazioni
  1. 9 3
      Chapter 4/04.js

+ 9 - 3
Chapter 4/04.js

@@ -18,10 +18,16 @@ $(document).ready(function () {
     $speech.css('fontSize', num + 'px');
   });
 
-  $('p').eq(1).hide();
+  var $firstPara = $('p').eq(1);
+  $firstPara.hide();
   $('a.more').click(function (event) {
     event.preventDefault();
-    $('p').eq(1).slideDown('slow');
-    $(this).hide();
+    if ($firstPara.is(':hidden')) {
+      $firstPara.fadeIn('slow');
+      $(this).text('read less');
+    } else {
+      $firstPara.fadeOut('slow');
+      $(this).text('read more');
+    }
   });
 });