How to Control CSS Animations with JavaScript

When it comes to animations on the web, developers need to measure the animation’s requirements with the right technology — CSS or JavaScript. Many animations are manageable with CSS but JavaScript will always provide more control. With document.getAnimations, however, you can use JavaScript to manage CSS animations! The document.getAnimations method returns an array of CSSAnimation objects. CSSAnimation provides a host of information about the animation: playState, timeline, effect, and events like onfinish. You can then modify those objects to adjust animations: // Make all CSS animations on the page twice as fast document.getAnimations().forEach((animation) ={ animation.playbackRate... more →
Posted in: JavaScript

JavaScript print Events

Media queries provide a great way to programmatically change behavior depending on viewing state. We can target styles to device, pixel ratio, screen size, and even print. That said, it’s also nice to have JavaScript events that also allow us to change behavior. Did you know you’re provided events both before and after printing? I’ve always used @media print in stylesheets to control print display, but JavaScript provides beforeprint and afterprint events: function toggleImages(hide = false) { document.querySelectorAll('img').forEach(img ={ img.style.display = hide ? 'none' : ''; }); } // Hide images to save toner/ink during printing window.addEventListener('beforeprint',... more →
Posted in: JavaScript

What do you call an American with a Brain?

Q: What do you call a person from Maine with a brain?A: A Maineiac.Q: What do you call a person from California with a brain?A: Lost!Q: What do you call a person from Arkansas with a brain?A: A Yo’allI asked the Stanford Alpaca AI what you would call a resident of each US ‘with a brain’. I was hoping for some good ‘dad joke’ type answers. For example I asked Alpaca “What do you call a Texan Maps Mania… more →
Posted in: Interactive Maps

Detect Browser Bars Visibility with JavaScript

It’s one thing to know about what’s in the browser document, it’s another to have insight as to the user’s browser itself. We’ve gotten past detecting which browser the user is using, and we’re now into knowing what pieces of the browser UI users are seeing. Browsers provide window.personalbar, window.locationbar, and window.menubar properties, with the shape of { visible : /*boolean*/} as its value: if(window.personalbar.visible || window.locationbar.visible || window.menubar.visible) { console.log("Please hide your personal, location, and menubar for maximum screen space"); } What would you use these properties for? Maybe providing a warning to users... more →
Posted in: JavaScript

The City of Women Subway Map

Barcelona, like New York and London, now has a reimagined subway map designed to celebrate and recognise the lives of some of the city’s most remarkable women. The Barcelona City of Women subway map highlights the extraordinary contribution of women to the Catalan capital. On the Ciutat de Dones map every station on Barcelona’s metro network and all the stops on the city’s railway network has Maps Mania… more →
Posted in: Interactive Maps

Detect the Content Type in the Clipboard

A user’s clipboard is a “catch all” between the operating system and the apps employed on it. When you use a web browser, you can highlight text or right-click an image and select “Copy Image”. That made me think about how developers can detect what is in the clipboard. You can retrieve the contents of the user’s clipboard using the navigator.clipboard API. This API requires user permission as the clipboard could contain sensitive data. You can employ the following JavaScript to get permission to use the clipboard API: const result = await navigator.permissions.query({name: "clipboard-write"}); if (result.state === "granted" || result.state === "prompt") {... more →
Posted in: JavaScript

The Map of Home Heating

The Washington Post has been exploring how Americans heat their homes. Their are four main energy sources used by Americans to heat their homes: electricity, natural gas, propane and fuel oil. Which one is used is mainly determined by geographical and historical reasons.In How Americans Heat Their Homes the Post has produced a map which shows that fuel oil (in red) is the most used source of home Maps Mania… more →
Posted in: Interactive Maps

Supporting PDF Embeds in an Eleventy WebC Component

Way back in the old days, in August of 2021, I wrote up an example of adding support for Adobe’s PDF Embed API as an Eleventy plugin: "An Adobe PDF Embed Plugin for Eleventy". When I find time, I need to update that to the newest URL for the library, but more recently I was curious if I could recreate support using the WebC template language. While it was a bit difficult at times (and a big thank you goes to Zach for patiently helping me), I think it’s at a point now where it can be shared. I will warn folks that I’m still struggling a bit with the best way to work with WebC, and at least one feature I’m showing isn’t documented yet (but I’ve confirmed... more →
Posted in: JavaScript
1 76 77 78 79 80 221