Skip to content

Instantly share code, notes, and snippets.

@xdesro
Created June 1, 2021 18:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xdesro/95fd330b71c10dca6afdf57cfb7590e0 to your computer and use it in GitHub Desktop.
Save xdesro/95fd330b71c10dca6afdf57cfb7590e0 to your computer and use it in GitHub Desktop.
Check if the current device is using a mouse with both CSS and JavaScript.
if (matchMedia('(pointer:fine)').matches) {
// This browser has a mouse or other fine-control device as its primary input.
}
.some-element {
/* Standard, mouseless behavior */
@media (pointer: fine) {
/* Progressively enhance to when more fine control is available. */
/* This can be useful for animations, or for click targets
e.g. checkboxes can be smaller when it is easier to click on them. */
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment