forked from devtlv/Ressource_JavaScript_Bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·33 lines (29 loc) · 987 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$(document).ready(function () {
// add change class to toggler
$('.navbar-toggler').click(function () {
$('.navbar-toggler').toggleClass('change');
});
// Dynamically determine the height of the navbar
let navHeight = $('.navbar').outerHeight();
// fix the navbar to the top when I scroll down
$(window).scroll(function () {
let position = $(this).scrollTop();
if (position >= navHeight) {
$('.navbar').addClass('fixed-top');
$('#header').css("padding-top", navHeight);
} else {
$('.navbar').removeClass('fixed-top');
$('#header').css("padding-top", "0");
}
});
// smooth scrolling
$('.nav-item a').click(function (link) {
link.preventDefault();
let target = $(this).attr('href');
$('html, body').stop().animate({
// Offset the scroll by the height of navbar to
// show all the section content
scrollTop: $(target).offset().top - navHeight
}, 1800);
});
}); // end of document ready