You need add some JS to do scroll events. The good way to do this is to set a new CSS class for the fixed position that will get assigned to the relevant div when scrolling goes past a certain point.
You can see the example below:
HTML :
CSS :
.header-fixed {
position: fixed;
top:0;
left:0;
width: 100%;
}
Jquery :
$(window).scroll(function(){
var header = $('.header'),
scroll = $(window).scrollTop();
if (scroll >= 100) header.addClass('header-fixed');
else header.removeClass('header-fixed');
});
This is the best way for fix header on page scroll.
I hope this blog has been helpful to understand a header fix on page scroll.
Thanks
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Himanshu Khurana
Himanshu is an experienced Frontend developer with experience and capabilities to build compelling UI's for Web and Mobile Applications. Himanshu likes playing cricket and listening music.