Technology News

Scroll Shadows With JavaScript

Scroll shadows are when you can see a little inset shadow on elements if (and only if) you can scroll in that direction. It’s just good UX. You can actually pull it off in CSS, which I think is amazing and one of the great CSS tricks. Except… it just doesn’t work on iOS Safari. It used to work, and then it broke in iOS 13, along with some other useful CSS things, with no explanation why and has never been fixed.

So, now, if you really want scroll shadows (I think they are extra useful on mobile browsers anyway), it’s probably best to reach for JavaScript.

Here’s a pure CSS example so you can see it work in all browsers except iOS Safari. Screenshots:

I’m bringing this up now because I see Jonnie Hallman is blogging about tit again. He mentioned it as an awesome little detail back in May. There are certain interfaces where scroll shadows really extra make sense.

Taking a step back, I thought about the solution that currently worked, using scroll events. If the scroll area has scrolled, show the top and left shadows. If the scroll area isn’t all the way scrolled, show the bottom and right shadows. With this in mind, I tried the simplest, most straight-forward, and least clever approach by putting empty divs at the top, right, bottom, and left of the scroll areas. I called these “edges”, and I observed them using the Intersection Observer API. If any of the edges were not intersecting with the scroll area, I could assume that the edge in question had been scrolled, and I could show the shadow for that edge. Then, once the edge is intersecting, I could assume that the scroll area has reached the edge of the scroll, so I could hide that shadow.

Clever clever. No live demo, unfortunately, but read the post for a few extra details on the implementation.

Other JavaScript-powered examples

I do think if you’re going to do this you should go the IntersectionObserver route though. Would love to see someone port the best of these ideas all together (wink wink).

Walking Dead: World Beyond Season 2 Clip Teases Jadis’ Journey With The CRM
Facebook’s whistleblower tells Congress how to regulate tech

Related Articles

8 Conversion-Driving UX Tactics For Ecommerce Websites

8-conversion-driving-ux-tactics-for-ecommerce-websites
Positive user experience (UX) is a prerequisite for retaining buyers, boosting eCommerce SEO results, and increasing website conversion rates.  In this post, we’ll discuss actionable UX design tactics that’ll help…

10 Fantastic Examples of Progressive Webapps

10-fantastic-examples-of-progressive-webapps
The concept of a progressive webapp (PWA) is simple. Developers create websites that behave like native applications for all environments. These work like hybrid site-app combos where you have “webapps”…

What is Chromium Without Chrome on Top?

what-is-chromium-without-chrome-on-top
Raw Chromium, perhaps? So, Chrome is based on Chromium which is open-source. Chrome is Chromium with Google’s extra stuff on top of it. What extra stuff? Kinda lots! A few…

CSS Hell

css-hell
There is a life beyond pixels and percentages. Using px units is fine in certain cases, the real mistake is using absolute instead of relative units. p {font-size: 16px;line-height: 20px;margin-bottom:…