JSFiddle - React, Tailwind, and code Playground
HTML
<input class="login_reg_input" value="click me">
JavaScript
$('input.login_reg_input').focus(function () {
var $elem = $(this),
cnt = 0,
from = { // animate from white (reg, green, blue) 255
r: 255,
g: 255,
b: 255
},
to = { // to #778899 (119, 102, 136)
r: 119,
g: 102,
b: 136
};
// interpolate "from" color to the "to" color
$(from).animate(to, {
duration: 1000,
step: function(now) {
// step is invoked for each r, g and b.
if (++cnt % 3 === 0) { // I want to process only when the whole triple is interpolated
$elem.css('background-color',
'rgb('
+ Math.round(this.r) + ','
+ Math.round(this.g) + ','
+ Math.round(this.b) + ')');
}
// confused? Just uncomment line below and you will get the hang of it
// console.log(now, this);
}
});
});