[0] | 1 | jQuery.fn.backgroundFade = function(s,callback) { |
---|
| 2 | var defaults = { |
---|
| 3 | sColor: [255,0,0], |
---|
| 4 | eColor: [255,255,255], |
---|
| 5 | fColor: null, |
---|
| 6 | steps: 200, |
---|
| 7 | intervals: 5, |
---|
| 8 | powr: 4 |
---|
| 9 | }, |
---|
| 10 | |
---|
| 11 | params = jQuery.extend(defaults,s); |
---|
| 12 | |
---|
| 13 | return this.each(function() { |
---|
| 14 | this.bgFade_sColor = jQuery.backgroundFade.parseHexColor(params.sColor); |
---|
| 15 | this.bgFade_eColor = jQuery.backgroundFade.parseHexColor(params.eColor); |
---|
| 16 | this.bgFade_fColor = params.fColor ? params.fColor : jQuery(this).css('backgroundColor'); |
---|
| 17 | this.bgFade_steps = params.steps; |
---|
| 18 | this.bgFade_intervals = params.intervals; |
---|
| 19 | this.bgFade_powr = params.powr; |
---|
| 20 | this.bgFade_fn = callback; |
---|
| 21 | |
---|
| 22 | jQuery.backgroundFade.doFade(this); |
---|
| 23 | }); |
---|
| 24 | }; |
---|
| 25 | |
---|
| 26 | jQuery.backgroundFade = { |
---|
| 27 | parseHexColor: function(c) { |
---|
| 28 | if (c.constructor == String && c.substr(0,1) == '#') { |
---|
| 29 | return [parseInt(c.substr(1,2),16),parseInt(c.substr(3,2),16),parseInt(c.substr(5,2),16)]; |
---|
| 30 | } |
---|
| 31 | return c; |
---|
| 32 | }, |
---|
| 33 | |
---|
| 34 | easeInOut: function(minValue,maxValue,totalSteps,actualStep,powr) { |
---|
| 35 | var delta = maxValue - minValue; |
---|
| 36 | var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta); |
---|
| 37 | return Math.ceil(stepp); |
---|
| 38 | }, |
---|
| 39 | |
---|
| 40 | doFade: function(e) { |
---|
| 41 | if (e.bgFadeInt) window.clearInterval(e.bgFadeInt); |
---|
| 42 | var act_step = 0; |
---|
| 43 | |
---|
| 44 | e.bgFadeInt = window.setInterval(function() { |
---|
| 45 | e.style.backgroundColor = |
---|
| 46 | "rgb("+ |
---|
| 47 | jQuery.backgroundFade.easeInOut(e.bgFade_sColor[0],e.bgFade_eColor[0], |
---|
| 48 | e.bgFade_steps,act_step,e.bgFade_powr)+","+ |
---|
| 49 | jQuery.backgroundFade.easeInOut(e.bgFade_sColor[1],e.bgFade_eColor[1], |
---|
| 50 | e.bgFade_steps,act_step,e.bgFade_powr)+","+ |
---|
| 51 | jQuery.backgroundFade.easeInOut(e.bgFade_sColor[2],e.bgFade_eColor[2], |
---|
| 52 | e.bgFade_steps,act_step,e.bgFade_powr)+")"; |
---|
| 53 | |
---|
| 54 | act_step++; |
---|
| 55 | if (act_step > e.bgFade_steps) { |
---|
| 56 | window.clearInterval(e.bgFadeInt); |
---|
| 57 | e.bgFade_sColor = undefined; |
---|
| 58 | e.bgFade_eColor = undefined; |
---|
| 59 | e.bgFade_fColor = undefined; |
---|
| 60 | e.bgFade_steps = undefined; |
---|
| 61 | e.bgFade_intervals = undefined; |
---|
| 62 | e.bgFade_powr = undefined; |
---|
| 63 | if (typeof(e.bgFade_fn) == 'function') { |
---|
| 64 | e.bgFade_fn.call(e); |
---|
| 65 | } |
---|
| 66 | e.style.backgroundColor = e.bgFade_fColor; |
---|
| 67 | } |
---|
| 68 | },e.bgFade_intervals); |
---|
| 69 | } |
---|
| 70 | }; |
---|