var shadowTexts = $('.cursor-shadow'), arrayLetters; $.each(shadowTexts, function () { var i = 0; if (this.innerHTML !== undefined) { arrayLetters = this.innerHTML.split(''); for (i = 0; i < arrayLetters.length; i++) { arrayLetters[i] = '' + arrayLetters[i] + ''; } this.innerHTML = arrayLetters.join(''); arrayLetters = $(this).find('span'); } }); function handleMouseMove(e) { $(arrayLetters).each(function () { var shadowStepY = ($(this).offset().top - e.y) / 300, shadowStepX = ($(this).offset().left - e.x) / 300, fullTextShadow = '0px 0px 0px #000', i = 1; for (i = 1; i < 20; i += 2) { fullTextShadow += ', ' + (shadowStepX * i) + 'px ' + (shadowStepY * i) + 'px 1px rgba(10,10,10,' + (3 / i) + ')'; } $(this).css({ 'text-shadow': fullTextShadow }); }); } document.onmousemove = handleMouseMove;