I am new to jQuery and need to figure out how to disable the transition on load for my navigation bar. Currently, when you load a page, the navigation bar transitions in with a big white bar and then settles.
Here is what I have. It works beautifully for the navigation bar to disappear on page scroll up; the only issue is on the initial page load, I do not want any transitioning.
<script>
jQuery(function($) {
var topPosition = 0;
$(window).scroll(function() {
var scrollMovement = $(window).scrollTop();
if (topPosition < 200) {
// Add any additional logic for topPosition less than 200 if needed
} else {
if (scrollMovement > topPosition) {
$('#global-header-section').removeClass('show-header');
$('#global-header-section').addClass('hide-header');
} else {
$('#global-header-section').removeClass('hide-header');
$('#global-header-section').addClass('show-header');
}
}
topPosition = scrollMovement;
});
});
</script>
<style>
#main-content {
margin-top: 7vw;
}
.hide-header {
opacity: 0;
margin-top: -200px !important;
}
.show-header {
opacity: 1;
margin-top: 0px !important;
}
#global-header-section {
-webkit-transition: all 0.5s ease !important;
-moz-transition: all 0.5s ease !important;
-o-transition: all 0.5s ease !important;
-ms-transition: all 0.5s ease !important;
transition: all 0.5s ease !important;
}
</style>
Add a class to #global-header-section div and name it disable-transition to disable the transition on page load.
When page fully loaded, activate the transition. You can ajust the timing.
Here is an example below. on how you can go about it.