Hi, I’m pretty new to Webflow and digital design world in general.
I want to build a mouseover flashlight on an image with a white background instead of using a completely black color. Ideally, when the mouse hovers certain area you will see the image. But I cannot find tutorials that teach me how to build it.
No, the website you shared they are just hovering over states not what I’m looking for… I want the effect follows the mouse. I think it would like Paper.js onMouseMove Paper.js — Tool
2 years later, but I came across this discussion as I was looking to do the same thing. Hopefully, this can help someone looking to do this in the future.
Add this your head tag and you will get what Ying has referenced.
<style>
/* Flashlight Overlay */
:root {
cursor: none;
--cursorX: 50vw;
--cursorY: 50vh;
}
:root:before {
content: '';
display: block;
width: 100%;
height: 100%;
position: fixed;
pointer-events: none;
background: radial-gradient(
circle 10vmax at var(--cursorX) var(--cursorY),
rgba(0,0,0,0) 0%,
rgba(0,0,0,0) 80%,
rgba(255,255,255,1) 100%
)
}
</style>
<script>
function update(e){
var x = e.clientX || e.touches[0].clientX
var y = e.clientY || e.touches[0].clientY
document.documentElement.style.setProperty('--cursorX', x + 'px')
document.documentElement.style.setProperty('--cursorY', y + 'px')
}
document.addEventListener('mousemove',update)
document.addEventListener('touchmove',update)
</script>