forked from heyimjuani/iluminate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.iluminate.js
65 lines (50 loc) · 2.32 KB
/
jquery.iluminate.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(function($) {
$.fn.iluminate = function( options ) {
var settings = $.extend({
size : 100,
dropoffStart : 0.6
}, options);
return this.each( function() {
var elSize = $(this).height();
// parent bg color will determine the shadow color
var bg = $(this).parent().css("background-color");
var darkerBG = $.xcolor.opacity(bg, 'black', 0.05);
// generate shadows and offset
var shadows = [];
var shadowSize = settings.size;
var dropoffStart = Math.ceil(shadowSize*settings.dropoffStart);
for (var i = 0; i < shadowSize; i++) {
if (i <= dropoffStart) {
var tweenedBG = $.xcolor.gradientlevel(darkerBG, bg, dropoffStart-i, dropoffStart);
shadow = (shadowSize - i) + "px " + (shadowSize - i) + "px " + tweenedBG;
}
else {
shadow = (shadowSize - i) + "px " + (shadowSize - i) + "px " + darkerBG;
}
shadows.push(shadow);
}
// get the shadows on a string so we can use them later
var shadowString = shadows.reverse().join();
// we'll need this element's background to set the text shadow color
var txc = $(this).css("background-color");
var darkerTX = $.xcolor.opacity(txc, 'black', 0.05);
var convertedTX = darkerTX.getRGB();
var RGBarrayTX = [];
$.each(convertedTX, function(key, value){
RGBarrayTX.push(value);
});
var RGBvaluesTX = RGBarrayTX[0] + ", " + RGBarrayTX[1] + ", " + RGBarrayTX[2];
// generate shadows and offset
var textShadows = [];
for (var i = 0; i < elSize/2; i++) {
textShadow = " " + (elSize/2 - i) + "px " + (elSize/2 - i) + "px rgb(" + RGBvaluesTX + ")";
textShadows.push(textShadow);
}
// get the shadows on a string so we can use them later
var textShadowString = textShadows.reverse().join();
// apply shadows
$(this).css("box-shadow", shadowString);
$(this).find("span").css("text-shadow", textShadowString);
});
};
}(jQuery));