Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 1st, 2012  |  syntax: None  |  size: 1.79 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. jQuery: how to stop a user triggering the same event before the first one one is finished
  2. $('#next').click(function() {
  3.     var currentMargin = $('#slider').attr('style');
  4.  
  5.     var number = currentMargin.match(/-?[0-9]+/);
  6.     var position = number - 993;
  7.  
  8.     $('#slider').animate({
  9.         marginLeft: position,
  10.     }, 1000, 'easeInQuad', function() {
  11.         console.log('done');
  12.     });
  13. });
  14. $('#back').click(function() {
  15.     var currentMargin = $('#slider').attr('style');
  16.  
  17.     var number = currentMargin.match(/-?[0-9]+/);
  18.     var num = new Number(number)
  19.     var position = num + 993;
  20.     console.log(position);
  21.     $('#slider').animate({
  22.         marginLeft: position,
  23.     }, 500, 'easeInQuad', function() {
  24.         console.log('done');
  25.     });
  26. });
  27.        
  28. $('#next').click(function() {
  29.     if ( $("#slider").data('inprogress') != true ) {
  30.  
  31.         $("#slider").data('inprogress',true);
  32.  
  33.         var currentMargin = $('#slider').attr('style');
  34.  
  35.         var number = currentMargin.match(/-?[0-9]+/);
  36.         var position = number - 993;
  37.  
  38.         $('#slider').animate({
  39.             marginLeft: position,
  40.         }, 1000, 'easeInQuad', function() {
  41.             console.log('done');
  42.             $("#slider").data('inprogress',false);
  43.         });
  44.  
  45.       }
  46.   });
  47.   $('#back').click(function() {
  48.     if ( $("#slider").data('inprogress') != true ) {
  49.  
  50.         $("#slider").data('inprogress',true);
  51.  
  52.  
  53.         var currentMargin = $('#slider').attr('style');
  54.  
  55.         var number = currentMargin.match(/-?[0-9]+/);
  56.         var num = new Number(number)
  57.         var position = num + 993;
  58.         console.log(position);
  59.         $('#slider').animate({
  60.             marginLeft: position,
  61.         }, 500, 'easeInQuad', function() {
  62.             console.log('done');
  63.             $("#slider").data('inprogress',false);
  64.         });
  65.     }
  66.  
  67.   });