Answer the question
In order to leave comments, you need to log in
How to handle page height when going to anchors?
Hello. Anchors are installed on the site, and when you navigate through them, due to the header glued at the top, the page shifts below the anchor exactly to the height of this header. for the anchors on the index page, I made smooth scrolling.
$("a.slide_to_anchor").click(function () {
var elementClick = $(this).attr("href")
var destination = $(elementClick).offset().top - $("#undefined-sticky-wrapper").height(); // отнимаем высоту хедера
jQuery("html:not(:animated),body:not(:animated)").animate({scrollTop: destination}, 1000); // плавная анимация
return false;
});
Answer the question
In order to leave comments, you need to log in
As an option, when loading the page, check for an anchor in the address and scroll up to the height of the header.
window.onload = function(){
if(window.location.hash) {
//если есть якорь, то скроллим вниз на высоту шапки
} else {
//здесь если нет, можно убрать блок else
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question