Skip to content
Advertisement

Creating a transparent navbar in bootstrap to be use in Gatsby JS app

I am trying to use bootstrap 5 to make a scrolling transparent navbar, however I am using jQuery and I need to convert it to react or simple javascript.

Here’s my HTML:

JavaScript

And here’s my jQuery that I need to convert:

JavaScript

You can see the JSFIDDLE here: https://jsfiddle.net/bootstrapious/ravpqxok/

Any idea how can I transform this into react or javascript version?

Advertisement

Answer

use window.addEventListener to catch the scroll event and classList.add/ classList.remove to add remove the class. this.scrollY will give you he same result as

JavaScript

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement