Jump to content

Fixed header


Recommended Posts

To ensure your header stays fixed without issues and doesn’t shift the layout upward, you need to add a margin equal to the height of the fixed header.

For example, if you pay attention to the class added during scrolling, omg_im_fixed, it indicates that the header has been fixed. In this case, we add a layout offset equal to the height of the header.
 

.omg_im_fixed main { 
	margin-top: 379px; 
}

In this scenario, the layout won’t jump unexpectedly.

However, it’s better to calculate the header height using a JavaScript script and automatically set the offset distance for the layout.

This is a concept and requires further refinement.

Screenshot_12.jpg

Screenshot_11.jpg

Link to comment
Share on other sites

I have change:

Fixedheader.css

@media (min-width: 576px){
    .omg_im_fixed .modal-dialog {
        margin-top:379px!important;
    }
}

But it not work.

"However, it’s better to calculate the header height using a JavaScript script and automatically set the offset distance for the layout."

Have you a eksmpel on that?

I have this javascript rigt now.

$(document).ready(function () {
    $(window).scroll(function () {
        if ($(this).scrollTop() > 100) {
            $('#header').addClass("header_omg_im_scrolled");
            $('body').addClass("omg_im_fixed");
        } else {
            $('#header').removeClass("header_omg_im_scrolled");
            $('body').removeClass("omg_im_fixed");
        }
    });
});

 

Link to comment
Share on other sites


    var headerHeight = $('#header').outerHeight();

    $(window).scroll(function () {
        if ($(this).scrollTop() > 100) {
            $('#header').addClass("header_omg_im_scrolled");
            $('body').addClass("omg_im_fixed");
 
            $('main').css('padding-top', headerHeight + 'px');
        } else {
            $('#header').removeClass("header_omg_im_scrolled");
            $('body').removeClass("omg_im_fixed");
  
            $('main').css('padding-top', '0');
        }
    });

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...