Reduce navbar / bloc width on scrolling

I’m sure there is a javascript way to to this. But I have no idea how. Basically, I would like to have my fixed navigation bar to reduce from full width to a max width of 1140px as soon as I start to scroll down.

How would I do that?