Javatpoint Logo
Javatpoint Logo

jQuery sticky header

In this article, we will understand the sticky header using jquery. A sticky header or fixed header is a smart navigation tool for keeping the header of a website in the same place on the screen while the user scrolls down or scrolls up the page. It appears at the top of the page as soon as the user starts scrolling up.

Following are the examples of sticky Header.

Example 1:

Explanation:

In the above example, we created an example of fixed header by using the concept of jquery. In this we solve the problem by positioning the navigation bar on part of the screen, wherever the website user ends up. The following code is used to fix the header on the screen.

In the above code snippet, we have used the addClass() function to add the sticky class and removeClass() function to remove the sticky class. Sticky class is adding when scroll down the webpage and sticky class is removing when scroll up the webpage.

Output:

Following is the output of this example.

Jquery sticky header

In the following output, sticky class is added.

Jquery sticky header

Example 2:

Explanation:

In the above example, we created an example of fixed header by using the concept of jquery. In this we solve the problem by positioning the navigation bar on part of the screen, wherever the website user ends up. The following code is used to fix the header on the screen.

In the above code snippet, we have used the addClass() function to add the sticky class and removeClass() function to remove the sticky class. Sticky class is adding when scroll down the webpage and sticky class is removing when scroll up the webpage.

Output:

Following is the output of this example.

Jquery sticky header





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA