JSFiddle - React, Tailwind, and code Playground
HTML
<button class="button">
Button Text
<div class="highlight"></div>
</button>
CSS
.button {
border: 1px solid black;
width: 400px;
height: 70px;
}
.highlight {
height: 40px;
width: 40px;
background: radial-gradient(#e66465, #9198e5);
transform: translate(var(--x), var(--y));
}
JavaScript
var button = document.querySelector('.button');
var highlightDiv = document.querySelector('.highlight');
button.addEventListener('mouseover', (e) => {
const x = (e.pageX - button.offsetLeft - 300 / 2) + 15;
const y = (e.pageY - button.offsetTop - 100 / 2) + 15;
highlightDiv.style.setProperty('--x', `${x}px`);
highlightDiv.style.setProperty('--y', `${y}px`);
});