瀏覽代碼

Listing 4.12: toggling visibility with fadeToggle().

Frederic G. MARAND 8 年之前
父節點
當前提交
725725bf6d
共有 1 個文件被更改,包括 5 次插入5 次删除
  1. 5 5
      Chapter 4/04.js

+ 5 - 5
Chapter 4/04.js

@@ -22,12 +22,12 @@ $(document).ready(function () {
   $firstPara.hide();
   $('a.more').click(function (event) {
     event.preventDefault();
-    if ($firstPara.is(':hidden')) {
-      $firstPara.fadeIn('slow');
-      $(this).text('read less');
+    $firstPara.slideToggle('slow');
+    var $link = $(this);
+    if ($link.text() == 'read more') {
+      $link.text('read less');
     } else {
-      $firstPara.fadeOut('slow');
-      $(this).text('read more');
+      $link.text('read more');
     }
   });
 });