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)
Any idea?
Thanks
Axel
2
Answers
You could try something with an overlay with an inset shadow which tracks the mouse location.
To create a flashlight effect that reveals content behind a div on mouse move, you can use CSS and JavaScript. Here’s an example
In this code, we have a fixed div with the class "flashlight" that covers the entire screen. It has a radial gradient background that starts with a dark color (rgba(0, 0, 0, 0.8)) and transitions to transparent, creating a flashlight effect.
We use JavaScript to listen for the mousemove event on the document. On each mouse move, we update the background position of the div to match the mouse coordinates (x, y). This makes the center of the flashlight follow the mouse cursor. We also set the size of the background to create the desired radius for the flashlight effect.