forked from Pranav016/Hacktoberfest-PR-for-beginners
-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.js
51 lines (45 loc) · 1.29 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
let nCount = selector => {
$(selector).each(function () {
$(this)
.animate({
Counter: $(this).text()
}, {
// A string or number determining how long the animation will run.
duration: 4000,
// A string indicating which easing function to use for the transition.
easing: "swing",
/**
* A function to be called for each animated property of each animated element.
* This function provides an opportunity to
* modify the Tween object to change the value of the property before it is set.
*/
step: function (value) {
$(this).text(Math.ceil(value));
}
});
});
};
let a = 0;
$(window).scroll(function () {
// The .offset() method allows us to retrieve the current position of an element relative to the document
let oTop = $(".numbers").offset().top - window.innerHeight;
if (a == 0 && $(window).scrollTop() >= oTop) {
a++;
nCount(".rect > h1");
}
});
/**
*
* sticky navigation
*
*/
let navbar = $(".navbar");
$(window).scroll(function () {
// get the complete hight of window
let oTop = $(".section-2").offset().top - window.innerHeight;
if ($(window).scrollTop() > oTop) {
navbar.addClass("sticky");
} else {
navbar.removeClass("sticky");
}
});