This is for the fixed to top version of the Boostrap 4 navbar. Instead of setting the padding and top position in CSS, let's use JavaScript to get it dynamically.
It is best to use the pure JavaScript version. It will be executed earlier since it does not require jQuery to be loaded. The vanilla JavaScript version can be used in the <head>
section.
If you are a performance concerned developer, your scripts are probably in the footer just before </body>
. Therefore, there might be a slight delay before the jQuery snippet is executed. This can lead to elements jumping around...
For perfectly smooth transition, it is best to execute this JavaScript as soon as the DOM is rendered.