I'm trying to create some kind of flashlight effect. I have a div (fixed, radiant background, height and width 100%) masking the entire screen. On mouse move, I'd like to reveal what is behind the div in a flashlight way.
I don't find a way to make a portion of this div transparent (opacity: 0). See example attached:
The "Pré-inscription" button appears on mouse over, the gradiant remains around the mouse cursor (the circle is too small on the screenshot, I will make it bigger)
EDIT: for a better understanding, I created a Codepen. As you can see, the fixed radiant gradiant. The red circle should allow to see through the gradiant.
let magnifier = document.getElementById('magnifier')
let size = magnifier.offsetWidth
window.addEventListener('mousemove', (e) => {
magnifier.style.top = e.clientY - (size / 2)+'px'
magnifier.style.left = e.clientX - (size / 2)+'px'
})
#overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
background: rgb(255,215,108);
background: radial-gradient(circle, rgba(251, 92, 3, 1) 0%, rgba(255,215,108,1) 100%);
}
#magnifier {
position: absolute;
background: red;
width: 7rem;
height: 7rem;
border-radius: 100%;
top: -20rem;
left: -20rem;
}
<h1 class="text-7xl">Coming soon</h1>
<div id="overlay">
<div id="magnifier"></div>
</div>
Any idea? Thanks
Axel