Skip to content

Instantly share code, notes, and snippets.

@morphIsmail
Last active January 24, 2021 04:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morphIsmail/218945bf207720282a1b07d3395a719f to your computer and use it in GitHub Desktop.
Save morphIsmail/218945bf207720282a1b07d3395a719f to your computer and use it in GitHub Desktop.
Меню с плавной прокруткой на jQuery
$(document).ready(function () {
$('.nav a[href^="#"]').click(function () {//выбрать ссылки из меню
var offset = $('.nav').innerHeight();//Высота меню, получаем динамически
var target = $(this).attr('href');//Сохраняем значение атрибута href
$('html, body').animate({
scrollTop: $(target).offset().top - offset//вычесть высоту меню
}, 500);//время анимации
$('.nav a[href^="#"]').removeClass('active');//удалить класс active у всех пунктов меню
$(this).addClass('active');//добавить класс active активной ссылке
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment