Last active
April 2, 2020 07:47
-
-
Save oparisblue/c49a61dd61aaea1962929c004a52b179 to your computer and use it in GitHub Desktop.
StackOverflow's "Ultra Dark" floodlight effect implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:root { | |
--cursorX:50vw; | |
--cursorY:50vh; | |
} | |
body.theme-ultradark:after { | |
content: ''; | |
position: fixed; | |
display: block; | |
border-radius: 100%; | |
top: calc(var(--cursorY) - 100px); | |
left: calc(var(--cursorX) - 100px); | |
background-color: transparent; | |
width: 200px; | |
height: 200px; | |
backdrop-filter: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='flashlight'%3E%3CfeFlood result='floodFill' x='0' y='0' width='200' height='200' flood-color='white' flood-opacity='1' /%3E%3CfeBlend in='floodFill' in2='SourceGraphic' mode='overlay' /%3E%3C/filter%3E%3C/svg%3E#flashlight") brightness(500%) saturate(200%); | |
pointer-events: none; | |
z-index: 9999999999999; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (document.body.classList.contains('theme-ultradark')) { | |
document.addEventListener('mousemove', e => { | |
window.requestAnimationFrame(() => { | |
const X = e.clientX; | |
const Y = e.clientY; | |
document.documentElement.style.setProperty('--cursorX', X + 'px'); | |
document.documentElement.style.setProperty('--cursorY', Y + 'px'); | |
}); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
The actual SVG is inline in the backdrop-filter CSS, I've just copied it here too so we can get a better look at it. | |
--> | |
<svg xmlns='http://www.w3.org/2000/svg'> | |
<filter id='flashlight'> | |
<feFlood result='floodFill' x='0' y='0' width='200' height='200' flood-color='white' flood-opacity='1' /> | |
<feBlend in='floodFill' in2='SourceGraphic' mode='overlay' /> | |
</filter> | |
</svg> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment