Ver código fonte

Listing 3.15: working with factored button handling.

Frederic G. MARAND 8 anos atrás
pai
commit
3564fb0289
1 arquivos alterados com 5 adições e 4 exclusões
  1. 5 4
      Chapter 3/03.js

+ 5 - 4
Chapter 3/03.js

@@ -1,7 +1,7 @@
 $(document).ready(function () {
   'use strict';
 
-  $('#switcher h3').hover(function() {
+  $('#switcher  ').hover(function() {
     $(this).addClass('hover');
   }, function() {
     $(this).removeClass('hover');
@@ -12,7 +12,9 @@ $(document).ready(function () {
   'use strict';
 
   $('#switcher').click(function (event) {
-    $('#switcher button').toggleClass('hidden');
+    if (!$(event.target).is('button')) {
+      $('#switcher button').toggleClass('hidden');
+    }
   });
 });
 
@@ -29,7 +31,6 @@ $(document).ready(function () {
 
       $('#switcher button').removeClass('selected');
       $(event.target).addClass('selected');
-      event.stopPropagation();
     }
   });
-});
+});