Created
June 1, 2021 18:24
-
-
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.
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 (matchMedia('(pointer:fine)').matches) { | |
// This browser has a mouse or other fine-control device as its primary input. | |
} |
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
.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