Skip to main content
added 34 characters in body
Source Link
user1477388
  • 21.2k
  • 33
  • 151
  • 272

You can extend Desheng Li's method further by allowing an iterations count to do multiple flashes like so:

// Extend jquery with flashing for elements
$.fn.flash = function(duration, iterations) {
    duration = duration || 1000; // Default to 1 second
    iterations = iterations || 1; // Default to 1 iteration
    var iterationDuration = Math.floor(duration / iterations;iterations);
    
    for (var i = 0; i < iterations; i++) {
        this.fadeOut(iterationDuration).fadeIn(iterationDuration);
    }
    return this;
}

Then you can call the method with a time and number of flashes:

$("#someElementId").flash(1000, 4); // Flash 4 times over a period of 1 second

You can extend Desheng Li's method further by allowing an iterations count to do multiple flashes like so:

// Extend jquery with flashing for elements
$.fn.flash = function(duration, iterations) {
    duration = duration || 1000; // Default to 1 second
    iterations = iterations || 1; // Default to 1 iteration
    var iterationDuration = duration / iterations;
    
    for (var i = 0; i < iterations; i++) {
        this.fadeOut(iterationDuration).fadeIn(iterationDuration);
    }
}

Then you can call the method with a time and number of flashes:

$("#someElementId").flash(1000, 4); // Flash 4 times over a period of 1 second

You can extend Desheng Li's method further by allowing an iterations count to do multiple flashes like so:

// Extend jquery with flashing for elements
$.fn.flash = function(duration, iterations) {
    duration = duration || 1000; // Default to 1 second
    iterations = iterations || 1; // Default to 1 iteration
    var iterationDuration = Math.floor(duration / iterations);
    
    for (var i = 0; i < iterations; i++) {
        this.fadeOut(iterationDuration).fadeIn(iterationDuration);
    }
    return this;
}

Then you can call the method with a time and number of flashes:

$("#someElementId").flash(1000, 4); // Flash 4 times over a period of 1 second
added 4 characters in body
Source Link
Dan Atkinson
  • 11.6k
  • 14
  • 84
  • 116

You can extend Desheng Li's method further by allowing an iterations count to do multiple flashes like so:

// Extend jquery with flashing for elements
$.fn.flash = function(duration, iterations) {
    duration = duration || 1000; // Default to 1 second
    iterations = iterations || 1; // Default to 1 iteration
    var iterationDuration = duration / iterations;
    
    for (var i = 0; i < iterations; i++) {
        this.fadeOut(iterationDuration).fadeIn(iterationDuration);
    }
}

Then you can call the method with a time and number of flashes:

$("#someElementId").flash(1000, 4); // Flash 4 times over a period of 1 second

$("#someElementId").flash(1000, 4); // Flash 4 times over a period of 1 second

You can extend Desheng Li's method further by allowing an iterations count to do multiple flashes like so:

// Extend jquery with flashing for elements
$.fn.flash = function(duration, iterations) {
    duration = duration || 1000; // Default to 1 second
    iterations = iterations || 1; // Default to 1 iteration
    var iterationDuration = duration / iterations;
    
    for (var i = 0; i < iterations; i++) {
        this.fadeOut(iterationDuration).fadeIn(iterationDuration);
    }
}

Then you can call the method with a time and number of flashes:

$("#someElementId").flash(1000, 4); // Flash 4 times over a period of 1 second

You can extend Desheng Li's method further by allowing an iterations count to do multiple flashes like so:

// Extend jquery with flashing for elements
$.fn.flash = function(duration, iterations) {
    duration = duration || 1000; // Default to 1 second
    iterations = iterations || 1; // Default to 1 iteration
    var iterationDuration = duration / iterations;
    
    for (var i = 0; i < iterations; i++) {
        this.fadeOut(iterationDuration).fadeIn(iterationDuration);
    }
}

Then you can call the method with a time and number of flashes:

$("#someElementId").flash(1000, 4); // Flash 4 times over a period of 1 second
Source Link
Rob Evans
  • 6.9k
  • 5
  • 41
  • 57

You can extend Desheng Li's method further by allowing an iterations count to do multiple flashes like so:

// Extend jquery with flashing for elements
$.fn.flash = function(duration, iterations) {
    duration = duration || 1000; // Default to 1 second
    iterations = iterations || 1; // Default to 1 iteration
    var iterationDuration = duration / iterations;
    
    for (var i = 0; i < iterations; i++) {
        this.fadeOut(iterationDuration).fadeIn(iterationDuration);
    }
}

Then you can call the method with a time and number of flashes:

$("#someElementId").flash(1000, 4); // Flash 4 times over a period of 1 second