彩虹字

let angle = 0;
let p = document.querySelector('p');
let text = p.textContent.split('');
let len = text.length;
let phaseJump = 360 / len;
let spans;

p.innerHTML = text.map(function (char) {
    return '' + char + '';
}).join('');

spans = p.children;
(function wheee() {
    for (var i = 0; i < len; i++) {
        spans[i].style.color = 'hsl(' + (angle + Math.floor(i * phaseJump)) + ', 55%, 70%)';
    }
    angle++;
    requestAnimationFrame(wheee);
})();

拼搏过的人生,即便没有成功。也只是不完美,但是它完整!


你可能感兴趣的:(彩虹字)