Revisions

gist: 179245 Download_button fork
public
Public Clone URL: git://gist.github.com/179245.git
Embed All Files: show embed
jquery-blink.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(function($){
  $.blink = {}
  $.blink.defaults = {
    "values": ["red", "orange", "yellow", "green", "aqua", "blue", "violet"],
    "rate": 150,
    "start_index": 0,
    "property": "color",
    "new_index":
      function(i, colors) {
        return (i + 1) % colors.length
      }
    }
  $.fn.blink = function(options) {
    var settings = $.extend({}, $.blink.defaults, options);
    return $(this).each(function() {
      $(this).data("blink_settings", settings);
      $(this).data("blink_index", settings.start_index);
      $(this).bind("blink.changeValue", function() {
        var $this = $(this);
        var settings = $this.data("blink_settings");
        var index = $this.data("blink_index");
        $this.css(settings.property, settings.values[index]);
        $this.data("blink_index", settings.new_index(index, settings.values));
 
        setTimeout(function() {
          $this.trigger("blink.changeValue");
        }, settings.rate);
      });
      $(this).trigger("blink.changeValue");
    });
  }
})(jQuery);