Wrap Up

You can still implement this behavior in JavaScript, but position: sticky has a few core benefits which give it the upper hand when it comes to development. Scroll listeners in JavaScript aren’t always the best solution: they can inhibit performance and are sometimes quite janky. Depending on the speed of scroll and the device someone is using, the listener might fall out-of-sync and need to catch up with a scroll, causing an element to jump into place instead of displaying a smooth locking behavior. Beyond performance concerns, it’s much simpler to write two lines of CSS than a bunch of JavaScript.