Using esc to close an image
How can I implement the use of "esc" key, or other accessibility features to close a pop-up image with this script?
It just display an image fixed.
11 Replies
Very basically this:
https://codepen.io/jochemm/pen/ExRRWMO?editors=1011
replace the
dialog.close()
with whatever you need to do to hide your image
but you've gotta listen for the keypress and then react to it
I'm such a slow typer lol
event.keyCode
is deprecated, you shouldn't use it anymore 🙂
you should use event.code
, and then compare against "Escape"Oh good to know 👍
Don't know why my VS code isn't showing that it's deprecated
I had to look it up on MDN to be sure
Thanks for the heads-up!
Doesn't e.key just say the name of the key e.g. ESC
"Escape", but yes
I was pretty close to this, but I guess I failed.
Thanks to you, and everyone 😊
I usually use e.key.tolowercase then check what I want
I was working with dialogs.
Made this function to close it when clicking, thinking it works outside of the content, but it closes anywhere.
Any clue what might be wrong?
The CSS is simply: