How to make specific actions when scroll reaches x position

So, how can I make the navbar, for example, change the size when the user scrolls down and be back to normal once it scrolls to the top? And can I make it at specific places so for example when it reaches x pixels or x percentage?

Hey Pedro,

nice to meet you! :wave:

You can read the current position in the viewport and change your styling depending on this.

If you give us a code project, e.g. on codepen,
we can show you some stuff.


This is what I currently have, I want to make the top bar smaller once the user starts scrolling.

Also is there a way to stop the images from moving when a border is added? It uses grid


Alright, so you have to find out these steps:

  1. how can I track a scroll event
  2. what should happen after the event happened

I already know what to do after it happens, I just can’t find out how to detect scrolling.

You can literally search for this (in quotes) and add javascript to the search