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
|
function interpolateStyle(el, prop, cb, reset = true) {
if (reset) {
el.style.setProperty(prop, '');
}
const intact = getComputedStyle(el);
const start = intact.getPropertyValue(prop);
try {
el.style.setProperty(prop, cb(start));
} catch (error) {}
}
function itpColor(prog, target) {
return start => {
const [ sr, sg, sb ] = start.match(/[0-9]{1,}/g).map(n => parseInt(n));
const [ tr, tg, tb ] = target.match(/[0-9]{1,}/g).map(n => parseInt(n));
const [ sh, ss, sl ] = rgbToHsl(sr, sg, sb);
const [ th, ts, tl ] = rgbToHsl(tr, tg, tb);
const [ ih, is, il ] = [
sh + prog * (th - sh),
ss + prog * (ts - ss),
sl + prog * (tl - sl)
];
const [ ir, ig, ib ] = hslToRgb(ih, is, il).map(n => parseInt(n));
return `rgb(${ir}, ${ig}, ${ib})`;
};
}
|