JavaScript Brightness
/**
* http://www.sitepoint.com/javascript-generate-lighter-darker-color/
*/
function colorLuminance(hex, lum) {
// Validate hex string
hex = String(hex).replace(/[^0-9a-f]/gi, "");
if (hex.length < 6) {
hex = hex.replace(/(.)/g, '$1$1');
}
lum = lum || 0;
// Convert to decimal and change luminosity
var rgb = '#', c;
for (var i = 0; i < 3; ++i) {
c = parseInt(hex.substr(i * 2, 2), 16);
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
rgb += ('00' + c).substr(c.length);
}
return rgb;
}
Penggunaan
colorLuminance('#aabbaa', 0.5); // lighter
colorLuminance('#aabbaa', -0.5); // darker
Labels: JavaScript, Potongan
7 Comments:
Mantab nih, pas lg nyari kak.
By IRIL SAGITA, at Tuesday, April 22, 2014 at 6:21:00 AM GMT+7
bisa dijadikan sebagai acuan dalam mengelola warna-warna yang diinginkan ini mas, makasih ya..
By Ana Sriwahyuni, at Tuesday, April 22, 2014 at 8:16:00 AM GMT+7
Turut menyimak aja mas. Kurang faham akan Js.
Ada page atau label untuk pemula nggak mas, saya suka coding juga sebenarnya, hanya saja tidak ada bimbingan dan tak cukup waktu untuk memulai.
Terima kasih sudah berbagi "Javascript Brigthness".
Salam. DTE.
By Anonymous, at Tuesday, April 22, 2014 at 6:42:00 PM GMT+7
Ke utara sedikit pak, terus belok kiri.
[img]http://3.bp.blogspot.com/-1uVrAYRVXkQ/U1cx9_XmBoI/AAAAAAAAIiQ/Vt7FLfyE46c/s1600/2014-04-23_101709.png[/img]
By Taufik Nurrohman, at Wednesday, April 23, 2014 at 10:23:00 AM GMT+7
saya suka sama mas taufik,,, minta otaknya dikit donk mas :D
By Rdk, at Tuesday, May 6, 2014 at 9:11:00 AM GMT+7
iya, aku juga minta donk mas :D
By Unknown, at Tuesday, May 6, 2014 at 1:03:00 PM GMT+7
Maaf, ini limited edition :p
By Taufik Nurrohman, at Tuesday, May 6, 2014 at 7:57:00 PM GMT+7
Post a Comment
<< Home