Improving icons visibility


Our navbar gained a nice scroll animation, but the icons on the right side lost their visibility.

We need to improve this.

Step 1 - add .text-white to the icons

In each <a> element inside <div id="navbar-icons"> we need to replace the ..text-neutral-600 class with the .text-white class:

Step 2 - update animated navbar javascript

We need to make a small update to our src/js/index.js file, so it includes the icons:

What we do here:

  1. We store the <div id="navbar-icons"> with its content in a variable using the getElementById method and the id of the <div> containing icons
  2. We store the <a> elements in a variable using the querySelectorAll method and the <a> elements inside the <div id="navbar-icons">
  3. We remove the .text-white class from the <a> elements inside the <div id="navbar-icons"> and add the .text-neutral-500 class
  4. We add the .text-white class to the <a> elements inside the <div id="navbar-icons"> and remove the .text-neutral-500 class when user scrolls up to the top of the page

Now the icons are white when the navbar is transparent and in the initial position, and they take on a more delicate gray color when we start scrolling and the navbar becomes white.

Step 3 - change the height on scroll

We can further diversify our scroll animation by changing the height of the navbar (specifically by changing its padding).

Update src/js/index.js as follow:

What we do here:

  1. We remove the .lg:py-4 class and add the .lg:py-5 class to the navbar when user scrolls down
  2. We remove the .lg:py-5 class and add the .lg:py-4 class to the navbar when user scrolls up to the top of the page

To make the animation smooth, we also need to update our CSS code and add padding 0.5s ease-in-out to it:

Now look how nice and smooth our animation is:

So at the end this is how our index.html file looks like:

And this is how our src/js/index.js file should look like:

If something is unclear or doesn't work as it should - hit me up on Twitter 😉




John Doe

About author

Michal Szymanski

Co Founder at TW Elements and MDBootstrap / Listed in Forbes „30 under 30" / Open-source enthusiast / Dancer, nerd & book lover.

Author of hundreds of articles on programming, business, marketing and productivity. In the past, an educator working with troubled youth in orphanages and correctional facilities.