-
Notifications
You must be signed in to change notification settings - Fork 0
/
janvi_portfolio.js
94 lines (84 loc) · 2.48 KB
/
janvi_portfolio.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
$(document).ready(function () {
var model = {
skillCounter: 0,
navToggled: false,
};
var app = {
init: function () {
this.cacheDOM();
this.bindEvents();
this.toggleScroll();
this.showSkill(model.skillCounter);
},
cacheDOM: function () {
this.$skill = document.getElementsByClassName("skill");
this.$skillArrow = $(".slider-arrow");
this.$navOverlay = $(".nav-overlay");
this.$toggleNav = $(".toggle-nav");
},
bindEvents: function () {
this.$skillArrow.on("click", this.skillSlider.bind(this));
this.$toggleNav.on("click", this.toggleNav.bind(this));
$(window).scroll(this.toggleScroll);
$('a[href*="#"]')
.not('[href="#"]')
.not('[href="#0"]')
.click(this.smoothScroll);
},
toggleScroll: function () {
if ($(document).scrollTop() > 0) {
$("nav").addClass("nav-scroll");
} else {
$("nav").removeClass("nav-scroll");
}
var scrollBarLocation = $(this).scrollTop();
$('a[href*="#"]')
.not('[href="#"]')
.not('[href="#0"]')
.each(function () {
var sectionOffset = $(this.hash).offset().top;
if (Math.floor(sectionOffset) <= scrollBarLocation) {
$(this).addClass("active");
$(this).siblings().removeClass("active");
} else {
$(this).removeClass("active");
}
});
},
showSkill: function (j) {
var length = this.$skill.length;
for (var i = 0; i < length; i++) {
$(this.$skill[i]).hide();
}
$(this.$skill[j]).show();
},
skillSlider: function (e) {
var i = $(e.target).attr("value");
model.skillCounter += Number(i);
if (model.skillCounter < 0) {
model.skillCounter = this.$skill.length - 1;
}
this.showSkill(model.skillCounter % this.$skill.length);
},
toggleNav: function () {
if (model.navToggled) {
this.$navOverlay.css("width", "0%");
model.navToggled = false;
} else {
this.$navOverlay.css("width", "100%");
model.navToggled = true;
}
},
smoothScroll: function (e) {
e.preventDefault();
model.navToggled ? app.toggleNav() : "";
$("html, body").animate(
{
scrollTop: $(this.hash).offset().top,
},
1000
);
},
};
app.init();
})();