Get a random item from array
randomItem = items[Math.floor(Math.random() * items.length)];
/** * Determine the mobile operating system. * This function returns one of 'iOS', 'Android', 'Windows Phone', or 'unknown'. * * @returns {String} */ function getMobileOperatingSystem() { var userAgent = navigator.userAgent || navigator.vendor || window.opera; // Windows Phone must come first because its UA also contains "Android" if (/windows phone/i.test(userAgent)) { return "Windows Phone"; } if (/android/i.test(userAgent)) { return "Android"; } // iOS detection from: http://stackoverflow.com/a/9039885/177710 if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) { return "iOS"; } return "unknown"; }
The Houdini API is a set of low-level CSS and JavaScript APIs that give developers more control over rendering and styling in the browser. It lets you access the browser's rendering engine to extend CSS and write custom behaviors for styling.
Example: Custom Paint Worklet
CSS.paintWorklet.addModule('worklet.js');
worklet.js
class MyPaint { paint(ctx, size) { ctx.fillStyle = 'red'; ctx.fillRect(0, 0, size.width, size.height); } } registerPaint('my-paint', MyPaint);
CSS Usage:
.box { background: paint(my-paint); }
Provides more control over animations beyond the regular requestAnimationFrame.
Customizes how elements are laid out, useful for dynamic or grid-based layouts.
Programmatically interact with CSS values in a performant manner using Typed CSS Values.
var OSName - "Minor unknown OS"; if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows"; if (navigator.appVersion.indexOf("Mac")!=-1) OSName="ios - Apple Inc."; if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX"; if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux"; console.log(OSName);