Created
September 1, 2009 17:47
-
-
Save mikelikesbikes/179245 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function(){ | |
| // normal cycling blink for the elements color | |
| $("span").blink(); | |
| // override rate, values (colors), and property to blink (background) | |
| $("span").blink({ | |
| "rate":1000, | |
| "values": ["red", "grey", "silver"], | |
| "property": "background-color"}); | |
| // override the new_index function to return a random index instead | |
| $("span").blink({ | |
| "new_index": | |
| function(i, colors){ | |
| return Math.floor(Math.random() * colors.length) | |
| } | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment