TIL the JS Library Current Device
POSTED ON:
TAGS: js
I worked on a project where android phones and iOS Tablets were giving me WILDLY different results. WebKit Safari bug;
This libary does the following:
- It injects the OS, device type and position into the html element.
<html class="ios tablet landscape">
So you can do hacky things like:
.ios body {
background-color: red;
}
- You also can fire specific JS code based on that as well.
body.addEventListener("click", () => {
if (device.landscape()) {
console.log("I'm in landscape!")
}
});
You really shouldn't be targetting this level of specificity.
But then again, WebKit (Safari iOS) is a pain in the ass.
Reference
https://matthewhudson.github.io/current-device/
Related TILs
Tagged: js