Skip to content

Instantly share code, notes, and snippets.

@neodigm
Last active December 28, 2021 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neodigm/a94e11ee11357b9eeaaf116880b9fb8c to your computer and use it in GitHub Desktop.
Save neodigm/a94e11ee11357b9eeaaf116880b9fb8c to your computer and use it in GitHub Desktop.
A11y | Is keyboard navigation
// Change display attributes if the page is being navigated via kb
// I think this was an IEFE back in the day
// Useage:
/*
body:not([data-is-kb]) .h-vs__hidden,
body[data-is-kb="false"] .h-vs__hidden{ visibility: hidden; }
*/
"isKeyb": function( _bMode ){ // User navigation mode state
if( typeof _bMode !== "undefined" ){
if(_bKeyb !== _bMode){
_bKeyb = _bMode;
document.body.dataset.isKb = _bKeyb;
}
}
return _bKeyb;
}
window.addEventListener("click", function() {oTopmenu.isKeyb(false)}); // mouse state
window.addEventListener("keyup", function(e) { if(e.keyCode==9) oTopmenu.isKeyb(true); }); // kb state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment