Huy's Notes
Position Sticky

Position Sticky

#ui #javascript

Position sticky is around for a while, there is still one thing it does not do well, is providing a way to detect whenever an element is sticked or not.

The naive approach would be watching for scroll event, but this is a stupid solution, because it's an expensive operator that will cause jankiness.

A smoother way is using observers, it called IntersectionObserver, the usage is pretty simple:

let observer = new IntersectionObserver((entries, observer) => {
  for (entry of entries) {
    if (entry.isIntersecting) {
      // the element is sticked, do something



Referred in

If you think this note resonated, be it positive or negative, please feel free to send me an email and we can talk.