D
D
Denis2016-04-25 13:55:10
css
Denis, 2016-04-25 13:55:10

How to make the menu fixed after scrolling to a specific block?

How to make the menu fixed after scrolling to a specific block?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2016-04-25
@thewind

leafo.net/sticky-kit
bigspotteddog.github.io/ScrollToFixed
If you want to write it yourself, then listen for the scroll event and read the scrollTop coordinate (in the case of a vertical scroll). In this case, the coordinate must be compared with the absolute position of the block you need along the desired axis.

A
Alexander Alekseev, 2016-04-25
@shure348

$(function(){
$(window).scroll(function(){
if ( $(this).scrollTop() > height ){
$('.menu').addClass("fixed");
} else {
$ ('.menu.fixed').removeClass("fixed");
}
});
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question