Trying to blur website when webpage loses focus. I tried using OnBlur and Focusin/out
I tried using OnBlur with the body tag, the html tag. I tried even listeners, a bunch of different JS, and other stuff.
I’m trying to make it so my website fades into a gaussian-like blur with some text that says something like “come baaaackkk :(“ or something stupid like that
2
Answers
you will need to use the visibilitychange event for this. Try the code below:
The
document.hidden
checks if the tab is open, but not visible.You don’t need the
setTimemout
function, but I added it there so you can see it in action, and the overlay doesn’t get removed instantly.and the corresponding css:
If you want to see this in working take a better look at this codepen
This is a simple solution that uses CSS only.
Feel free to modify it to your needs