[syndicated profile] csstricks_feed

Posted by Zell Liew

In a previous article, I showed you how to refactor the Resize Observer API into something way simpler to use:

// From this
const observer = new ResizeObserver(observerFn)

function observerFn (entries) {
  for (let entry of entries) {
    // Do something with each entry
  }
}

const element = document.querySelector('#some-element')
observer.observe(element);
// To this 
const node = document.querySelector('#some-element')
const obs = resizeObserver(node, {
  callback({ entry }) {
    // Do something with each entry
  }
})

Today, we’re going to do the same for MutationObserver and IntersectionObserver.

Refactoring Mutation Observer

MutationObserver has almost the same API as that of ResizeObserver. So we can practically copy-paste the entire chunk of code we wrote for resizeObserver to mutationObserver.

export function mutationObserver(node, options = {}) {
  const observer = new MutationObserver(observerFn)
  const { callback, ...opts } = options
  observer.observe(node, opts)

  function observerFn(entries) {
    for (const entry of entries) {
      // Callback pattern
      if (options.callback) options.callback({ entry, entries, observer })
      // Event listener pattern
      else {
        node.dispatchEvent(
          new CustomEvent('mutate', {
            detail: { entry, entries, observer },
          })
        )
      }
    }
  }
}

You can now use mutationObserver with the callback pattern or event listener pattern.

const node = document.querySelector('.some-element')

// Callback pattern 
const obs = mutationObserver(node, {
  callback ({ entry, entries }) {
    // Do what you want with each entry
  }
})

// Event listener pattern
node.addEventListener('mutate', event => {
  const { entry } = event.detail
  // Do what you want with each entry
})

Much easier!

Disconnecting the observer

Unlike ResizeObserver who has two methods to stop observing elements, MutationObserver only has one, the disconnect method.

export function mutationObserver(node, options = {}) {
  // ... 
  return {
    disconnect() {
      observer.disconnect()
    }
  }
}

But, MutationObserver has a takeRecords method that lets you get unprocessed records before you disconnect. Since we should takeRecords before we disconnect, let’s use it inside disconnect.

To create a complete API, we can return this method as well.

export function mutationObserver(node, options = {}) {
  // ... 
  return {
    // ...
    disconnect() {
      const records = observer.takeRecords()
      observer.disconnect()
      if (records.length > 0) observerFn(records)
    }
  }
}

Now we can disconnect our mutation observer easily with disconnect.

const node = document.querySelector('.some-element')
const obs = mutationObserver(/* ... */)

obs.disconnect()

MutationObserver’s observe options

In case you were wondering, MutationObserver’s observe method can take in 7 options. Each one of them determines what to observe, and they all default to false.

  • subtree: Monitors the entire subtree of nodes
  • childList: Monitors for addition or removal children elements. If subtree is true, this monitors all descendant elements.
  • attributes: Monitors for a change of attributes
  • attributeFilter: Array of specific attributes to monitor
  • attributeOldValue: Whether to record the previous attribute value if it was changed
  • characterData: Monitors for change in character data
  • characterDataOldValue: Whether to record the previous character data value

Refactoring Intersection Observer

The API for IntersectionObserver is similar to other observers. Again, you have to:

  1. Create a new observer: with the new keyword. This observer takes in an observer function to execute.
  2. Do something with the observed changes: This is done via the observer function that is passed into the observer.
  3. Observe a specific element: By using the observe method.
  4. (Optionally) unobserve the element: By using the unobserve or disconnect method (depending on which Observer you’re using).

But IntersectionObserver requires you to pass the options in Step 1 (instead of Step 3). So here’s the code to use the IntersectionObserver API.

// Step 1: Create a new observer and pass in relevant options
const options = {/*...*/}
const observer = new IntersectionObserver(observerFn, options)

// Step 2: Do something with the observed changes
function observerFn (entries) {
  for (const entry of entries) {
    // Do something with entry
  }
}

// Step 3: Observe the element
const element = document.querySelector('#some-element')
observer.observe(element)

// Step 4 (optional): Disconnect the observer when we're done using it
observer.disconnect(element)

Since the code is similar, we can also copy-paste the code we wrote for mutationObserver into intersectionObserver. When doing so, we have to remember to pass the options into IntersectionObserver and not the observe method.

export function mutationObserver(node, options = {}) {
  const { callback, ...opts } = options
  const observer = new MutationObserver(observerFn, opts)
  observer.observe(node)

  function observerFn(entries) {
    for (const entry of entries) {
      // Callback pattern
      if (options.callback) options.callback({ entry, entries, observer })
      // Event listener pattern
      else {
        node.dispatchEvent(
          new CustomEvent('intersect', {
            detail: { entry, entries, observer },
          })
        )
      }
    }
  }
}

Now we can use intersectionObserver with the same easy-to-use API:

const node = document.querySelector('.some-element')

// Callback pattern 
const obs = intersectionObserver(node, {
  callback ({ entry, entries }) {
    // Do what you want with each entry
  }
})

// Event listener pattern
node.addEventListener('intersect', event => {
  const { entry } = event.detail
  // Do what you want with each entry
})

Disconnecting the Intersection Observer

IntersectionObserver‘s methods are a union of both resizeObserver and mutationObserver. It has four methods:

  • observe: observe an element
  • unobserve: stops observing one element
  • disconnect: stops observing all elements
  • takeRecords: gets unprocessed records

So, we can combine the methods we’ve written in resizeObserver and mutationObserver for this one:

export function intersectionObserver(node, options = {}) {
  // ...
  return {
    unobserve(node) {
      observer.unobserve(node)
    },

    disconnect() {
      // Take records before disconnecting.
      const records = observer.takeRecords()
      observer.disconnect()
      if (records.length > 0) observerFn(records)
    },
    
    takeRecords() {
      return observer.takeRecords()
    },
  }
}

Now we can stop observing with the unobserve or disconnect method.

const node = document.querySelector('.some-element')
const obs = intersectionObserver(node, /*...*/)

// Disconnect the observer
obs.disconnect()

IntersectionObserver options

In case you were wondering, IntersectionObserver takes in three options:

  • root: The element used to check if observed elements are visible
  • rootMargin: Lets you specify an offset amount from the edges of the root
  • threshold: Determines when to log an observer entry

Here’s an article to help you understand IntersectionObserver options.

Using this in practice via Splendid Labz

Splendid Labz has a utils library that contains resizeObserver, mutationObserver and IntersectionObserver.

You can use them if you don’t want to copy-paste the above snippets into every project.

import { 
  resizeObserver, 
  intersectionObserver, 
  mutationObserver 
} from 'splendidlabz/utils/dom'

const mode = document.querySelector(‘some-element’)

const resizeObs = resizeObserver(node, /* ... */)
const intersectObs = intersectionObserver(node, /* ... */)
const mutateObs = mutationObserver(node, /* ... */)

Aside from the code we’ve written together above (and in the previous article), each observer method in Splendid Labz is capable of letting you observe and stop observing multiple elements at once (except mutationObserver because it doesn’t have a unobserve method)

const items = document.querySelectorAll('.elements')
const obs = resizeObserver(items, {
  callback ({ entry, entries }) {
    /* Do what you want here */
  }
})

// Unobserves two items at once
const subset = [items[0], items[1]]
obs.unobserve(subset)

So it might be just a tad easier to use the functions I’ve already created for you. 😉

Shameless Plug: Splendid Labz contains a ton of useful utilities — for CSS, JavaScript, Astro, and Svelte — that I have created over the last few years.

I’ve parked them all in into Splendid Labz, so I no longer need to scour the internet for useful functions for most of my web projects. If you take a look, you might just enjoy what I’ve complied!

(I’m still making the docs at the time of writing so it can seem relatively empty. Check back every now and then!)

Learning to refactor stuff

If you love the way I explained how to refactor the observer APIs, you may find how I teach JavaScript interesting.

In my JavaScript course, you’ll learn to build 20 real life components. We’ll start off simple, add features, and refactor along the way.

Refactoring is such an important skill to learn — and in here, I make sure you got cement it into your brain.

That’s it! Hope you had fun reading this piece!


A Better API for the Intersection and Mutation Observers originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

Live

Jun. 23rd, 2025 01:50 pm
[syndicated profile] adactio_feed

Ever since Salter Cane recorded the songs on Deep Black Water I’ve been itching to play them live. At our album launch gig last Friday, I finally got my chance.

It felt soooo good! It helped that we had the best on-stage sound ever (note to the bands of Brighton, Leon at the Hope and Ruin is fantastic at doing the sound). The band were tight, the songs sounded great live, and I had an absolute blast.

Salter Cane on stage, with Chris in full howl singing into the mic and playing guitar, flanked by Jeremy on slide bouzouki and Jessica on bass (Matt on the drums is hidden behind Chris).

I made a playlist of songs to be played in between bands. It set the tone nicely. As well as some obvious touchstones like 16 Horsepower and Joy Division, I made sure to include some local bands we’re fond of, like The Equitorial Group, Mudlow, Patients, and The Roebucks.

Weekly Reading List June 23 2025

Jun. 23rd, 2025 05:20 am
[syndicated profile] paciellogroup_feed

Posted by Ricky Onsman

Weekly Reading List

W3C seeks community input for Board of Directors appointments

Chris Wilson: We are seeking the community’s help in order to identify candidates who might fill those gaps.

https://www.w3.org/blog/2025/w3c-seeks-community-input-for-board-of-directors-appointments/

 

Historic Declaration: United Nations Proclaims June 27 as International Day of Deafblindness

To promote the empowerment and inclusion of deafblind individuals in all aspects of society.

https://wfdb.eu/2025/06/16/historic-declaration-united-nations-proclaims-june-27-as-international-day-of-deafblindness/

 

Accessibility 100

Forbes’ first-ever Accessibility 100 highlights the biggest innovators and impact-makers in the field of accessibility for people with disabilities.

https://www.forbes.com/lists/accessibility-100/

 

Applications Open for the 2025 IAAP Impact Award

The Impact Award is given to a select few nominees that have made outstanding and impactful contributions to accessibility inclusion.

https://www.surveymonkey.com/r/2025ImpactAward_NominationForm

 

Book: Accessible UX Research

Michele A. Williams: Make your UX research inclusive. Learn how to recruit, plan, and design with disabled participants in mind. Published August 2025.

Vitaly Friedman: https://www.smashingmagazine.com/2025/06/accessible-ux-research-pre-release/

https://www.smashingmagazine.com/printed-books/accessible-ux-research/

 

#a11y folks: Quick poll.

Karl Groves: I have an idea for an accessibility conference that solely consists of half-day workshops.

https://www.linkedin.com/posts/karlgroves_a11y-activity-7341093586232373248-Ir5T/

 

Podcast: AXSChat with Susanna Laurin

Neil Milliken and Antonio Santos of ATOS interview one of the most knowledgeable accessibility people in Europe on the eve of the EAA coming into force.

https://www.axschat.com/axschat-with-susanna-laurin/

 

You’re not an accessibility specialist until you’ve…

Bogdan Cerovac: a reaction to last week’s "You’re not a front-end developer until you’ve…" [ it’s a long list ].

https://cerovac.com/a11y/2025/06/youre-not-an-accessibility-specialist-until-youve/

 

Testing Methods: Meaningful Sequence

Dennis Deacon: content should be understandable regardless of whether it’s read visually or by a screen reader.

https://www.dennisdeacon.com/web/accessibility/testing-methods-meaningful-sequence/

 

Applications that Create PDFs & Accessibility Output

Dennis Deacon: Some source applications do a better job at generating accessible PDF files.

https://www.dennisdeacon.com/web/accessibility/applications-that-create-pdfs-accessibility-output/

 

PDF Strategy in Improving Accessibility

Dennis Deacon: PDFs [ can ] completely block access for people who rely on assistive technology like screen
readers.

https://www.dennisdeacon.com/web/accessibility/pdf-strategy-in-improving-accessibility/

 

Testing Methods: Sensory Characteristics

Dennis Deacon: understanding and using content [ must ] not rely solely on sensory attributes like shape, color, size, visual position, orientation, or sound.

https://www.dennisdeacon.com/web/accessibility/testing-methods-sensory-characteristics/

 

Erring on the side of caution

Martin Underhill: WCAG conformance can be open to interpretation.

https://www.tempertemper.net/blog/erring-on-the-side-of-caution

 

A11y 101: 2.1.2 No Keyboard Trap

Nat Tarnoff: Make sure that a user doesn’t get trapped with no where to go.

https://tarnoff.info/2025/06/16/a11y-101-2-1-2-no-keyboard-trap/

 

Usability Testing in the Wild

Niq Bernadowitsch: User insights in exchange for user refreshments. [ how about paying them? ]

https://niqwithq.com/posts/usability-testing-in-the-wild

 

What I Wish Someone Told Me When I Was Getting Into ARIA

Eric Bailey: it’s everyone’s first time learning about ARIA at some point.

https://www.smashingmagazine.com/2025/06/what-i-wish-someone-told-me-aria/

 

Pseudomotion, Motion Sensitivity, and Accessibility

Sheri Byrne-Haber: both real and simulated motion can trigger symptoms such as nausea, dizziness, vertigo, migraines, or even seizures.

https://buttondown.com/access-ability/archive/pseudomotion-motion-sensitivity-and-accessibility/

 

Don’t use that accessibility overlay

Lucy Greco: These overlays have never really done what they claim.

https://accessaces.com/dont-use-that-accessibility-overlay/

 

Can accessibility be whimsical?

Sara Joy: Here’s where the idea for whimsica11y comes back – many people want their personal sites to be accessible.

https://goodinternetmagazine.com/can-accessibility-be-whimsical/

Whimsica11y: https://whimsica11y.net/

 

Navigating the Intersection of Accessibility and Measurement Integrity in eCOA

Paul O’Donohoe, Florence Mowlem: Clinical research evolves to prioritize patient-centered outcomes, integrating accessibility standards in electronic data capture for inclusive clinical trials.

https://www.appliedclinicaltrialsonline.com/view/navigating-the-intersection-of-accessibility-and-measurement-integrity-in-ecoa

 

Practical Tips for Mobile App Accessibility Implementation

Florian Schroiff: Improve your development skills to build apps for everyone.

https://www.a11y-collective.com/blog/mobile-app-accessibility/

 

10 Harsh Realities Every Digital Accessibility Consultant Needs to Hear

Monika Prasad: Digital accessibility consulting isn’t just a technical job—it’s a people job.

https://www.digitala11y.com/10-harsh-realities-every-digital-accessibility-consultant-needs-to-hear/

 

From Curiosity to Creation: The Story Behind Accessibility Nerd

Thomas Logan and Ken Nakata welcome Cameron Cundiff, the creator of A11y Agent (includes video demo).

https://equalentry.com/ai-accessibility/

 

Accessibility Terms Every Content Creator Should Know

Josh Crawford: This practical glossary breaks down essential accessibility terms.

https://www.digitalaccesstraining.com/pages/articles?p=accessibility-terms-every-content-creator-should-know

 

Selfish reasons for building accessible UIs

Nolan Lawson: No finger-wagging here: just good old hardheaded self-interest!

https://nolanlawson.com/2025/06/16/selfish-reasons-for-building-accessible-uis/

 

Accessibility in Design Systems

Sjoerd Beentjes: Design systems help with accessibility, but they’re not the full solution.

https://www.voorhoede.nl/en/blog/accessibility-in-design-systems/

 

Design Systems of the Future

Ben Callahan: responses to "tell us what you think tomorrow’s design system will or should look like."

https://bencallahan.com/design-system-of-the-future

 

The Role of Captions and Transcripts in Accessibility

Michael Beck: why captions and transcripts are critical for accessibility.

https://afixt.com/the-role-of-captions-and-transcripts-in-accessibility/

 

How to create an accessible color palette

Chris Ferdinandi: a sneak peak of the color palette generator I’m building.

https://gomakethings.com/how-to-create-an-accessible-color-palette/

 

Creating a semantic color palette

Chris Ferdinandi: create semantic color variables that we can use throughout our design system.

https://gomakethings.com/creating-a-semantic-color-palette/

 

TIL: Smart glasses aren’t just for pricks, they are an accessibility aid

Chris Heilmann: smart glasses aren’t just a gimmick for influencers or a privacy concern.

https://christianheilmann.com/2025/06/18/til-smart-glasses-arent-just-for-pricks-they-are-an-accessibility-aid/

 

Font size dimensions

Donnie D’Amato: The use of font size was highly misunderstood across our practice for years.

https://blog.damato.design/posts/font-size-dimensions/

 

Bluesky Likes Web Components

Lea Verou: the pain of building accessible, localizable web components in 2025.

https://lea.verou.me/blog/2025/bluesky-likes/

 

How Technology is Transforming Worship for Individuals with Disabilities

Technology is expanding access to faith and community.

https://www.respectability.org/2025/06/technology-transforming-worship/

 

Accessibility in Media

Grace Dow: Disability advocates are suing after the Trump administration abruptly stopped providing sign language interpreters at press briefings and other events.

https://gracedowwrites.com/2025/06/18/accessibility-in-media/

 

A Beginner’s Guide to Samsung TalkBack and How It Differs from Google’s Version

Kareen Kiwan: aims to highlight what’s available and what’s not in Samsung’s version of TalkBack.

https://accessibleandroid.com/a-beginners-guide-to-samsung-talkback-and-how-it-differs-from-googles-version/

 

Harker. Type Faster with Your Voice

A minimal and stylish speech-to-text widget for your [ Mac ] desktop. The fastest way from thought to text.

https://www.getharker.com/

 

Amazon improves Kindle accessibility with new text spacing adjustments

Andrew Liszewski: The latest software update for 11th and 12th generation Kindles greatly expands their text formatting options.

https://www.theverge.com/news/690259/amazon-kindle-software-update-accessibility-text-spacing-settings

 

Google’s June Pixel Drop

Steven Aquino: Includes Android 16 for Pixel Devices, Accessibility Improvements, More.

https://www.curbcuts.co/blog/2025-6-18-googles-june-pixel-drop-includes-android-16-for-pixel-devices-accessibility-improvements-more

 

NVDA 2025.1.2rc1 available for testing

This release includes a fix for a minor bug.

https://www.nvaccess.org/post/nvda-2025-1-2rc1/

 

Accessibility Checker Now Available in 32 Languages

Amber Hinds: Equalize Digital’s powerful WordPress plugin for automated accessibility testing and fixes.

https://equalizedigital.com/accessibility-checker-now-available-in-32-languages/

 

Online workshop: The New CSS Toolkit

Kevin Powell: We’ll be exploring powerful layout techniques and advanced CSS features (5 x 2.5h from 12/03/25, $350)

https://smashingconf.com/online-workshops/workshops/css-toolkit-kevin-powell

 

The Hamburger-Menu Icon Today: Is it Recognizable?

Kate Kaplan: the same old best practices for hidden navigation still apply.

https://www.nngroup.com/articles/hamburger-menu-icon-recognizability/

 

Just a designer now: Shopify dropped UX as a title

Ian Batterbee: but at what cost to user-centred design?

https://archive.md/HZabj

 

The post Weekly Reading List June 23 2025 appeared first on TPGi.

(no subject)

Jun. 21st, 2025 08:47 pm
raivotar: (Default)
[personal profile] raivotar posting in [community profile] style_system
hi again! i think how i can make my layout fonts looks like here -> sarliina.livejournal.com

codes: https://pastebin.com/zygPhnxZ

Profile

carene_waterman: An image of the Carina Nebula (Default)
carene_waterman

July 2014

S M T W T F S
  12345
6789101112
13141516171819
2021 22 2324 2526
2728293031  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 5th, 2025 01:31 pm
Powered by Dreamwidth Studios