Explorar o código

Listing 7.4: cycle pause/resume controls.

Frederic G. MARAND %!s(int64=9) %!d(string=hai) anos
pai
achega
b6c93e3c0f
Modificáronse 1 ficheiros con 10 adicións e 4 borrados
  1. 10 4
      Chapter 7/07.js

+ 10 - 4
Chapter 7/07.js

@@ -1,10 +1,16 @@
-$.fn.cycle.defaults.timeout = 10000;
-$.fn.cycle.defaults.random = true;
-
 $(document).ready(function () {
-  $('#books').cycle({
+  var $books = $('#books').cycle({
     timeout: 2000,
     speed: 200,
     pause: true
   });
+  var $controls = $('<div id="books-controls"></div>').insertAfter($books);
+  $('<button>Pause</button>').click(function (event) {
+    event.preventDefault();
+    $books.cycle('pause');
+  }).appendTo($controls);
+  $('<button>Resume</button>').click(function (event) {
+    event.preventDefault();
+    $books.cycle('resume');
+  }).appendTo($controls);
 });