Skip to content

Instantly share code, notes, and snippets.

@ihortkachuk
Created December 24, 2014 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihortkachuk/096890645f8f18b8e382 to your computer and use it in GitHub Desktop.
Save ihortkachuk/096890645f8f18b8e382 to your computer and use it in GitHub Desktop.
/**
* Для плавного перехода по ссылкам
*/
$(document).ready(function () {
$('.panel-nav a[href="#about-us"]').addClass('active');
$(document).on("scroll", onScroll);
//smoothscroll
$('.panel-nav a[href^="#"]').on('click', function (e) {
e.preventDefault();
$(document).off("scroll");
$('a').each(function () {
$(this).removeClass('active');
})
$(this).addClass('active');
var target = this.hash,
menu = target;
$target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top - 95
}, 1000, 'swing', function () {
window.location.hash = target;
$(document).on("scroll", onScroll);
});
});
});
function onScroll(event) {
var scrollPos = $(document).scrollTop();
if ($(window).scrollTop() + $(window).height() == $(document).height()) {
$('.panel-nav a').each(function () {
$(this).removeClass("active");
});
$('.panel-nav a[href="#support"]').addClass('active');
} else {
$('.panel-nav a').each(function () {
var currLink = $(this);
var refElement = $(currLink.attr("href"));
if (refElement.position().top - 95 <= scrollPos && refElement.position().top + refElement.height() > scrollPos) {
$('.panel-nav ul li a').removeClass("active");
currLink.addClass("active");
} else {
currLink.removeClass("active");
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment