-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
146 lines (122 loc) · 4.05 KB
/
script.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
let OCCUPATION_ROTATE_LENGTH = 4500;
let OCCUPATION_ANIMATION_LENGTH = 1000;
function project_factory(project_data){
project_name = project_data.name || "";
project_imgs = project_data.imgs || [];
project_year = project_data.year_made;
project_category = project_data.category || "";
project_description = project_data.description || "";
// project_description = "";
project_row = `<img class="project-image" src="${project_imgs[0]}">`
if(project_description !== ""){
project_row += `<p class="project-description">${project_description}</p>`
}
if(project_year !== undefined){
project_name += ` - ${project_year}`
}
return `
<div class="project-container">
<div class="project-column">
<h2 class="project-name">${project_name}</h2>
<div class="project-row">
${project_row}
</div>
</div>
</div>`
}
function slider_image_factory(sli){
}
function contact_page_factory(contact_info) {
project_name = contact_info.name || "";
project_year = contact_info.year_made;
project_img = contact_info.img;
if(project_year !== undefined){
project_name += ` ~ ${project_year}`
}
return `
<div class="contact-img-container">
<img id="contact-img" src="${project_img}" alt="${project_name}">
<h4 class="contact-img-desc"><i>${project_name}</i></h4>
</div>
`
}
function title_factory(index, title_name){
if(index == 0){
return `<h2 class="oc-text oc-text-shown">${title_name}</h2>`
}
return `<h2 class="oc-text">${title_name}</h2>`
}
function display_section(section_id) {
$("main section").each((key, val) => {
if($(val).attr('id') == section_id){
$(val).show();
}else{
$(val).hide();
}
});
go_to_top();
}
function set_active_menu(element) {
$(element).siblings().toggleClass('active', false);
$(element).toggleClass('active', true);
}
function is_in_view(element, fullyInView) {
var pageTop = $(window).scrollTop();
var pageBottom = pageTop + $(window).height();
var elementTop = $(element).offset().top;
var elementBottom = elementTop + $(element).height();
if (fullyInView === true) {
return ((pageTop < elementTop) && (pageBottom > elementBottom));
} else {
return ((elementTop <= pageBottom) && (elementBottom >= pageTop));
}
}
function go_to_top() {
window.scrollTo(0, 0);
}
let slides = document.getElementsByClassName("slider__slide");
let currentSlide = 0;
function changeSlide(moveTo) {
if (moveTo >= slides.length) {moveTo = 0;}
if (moveTo < 0) {moveTo = slides.length - 1;}
slides[currentSlide].classList.toggle("active");
slides[moveTo].classList.toggle("active");
currentSlide = moveTo;
}
$(window).scroll(function(){
if(is_in_view($("#title-link"), false)){
$("#menu-bar-icon-container").fadeOut();
}else{
if(!$("#menu-bar-icon-container").is(":visible")){
$("#menu-bar-icon-container").css("display", "flex").hide().fadeIn();
}
}
// Top button
if($("#project-section").is(":visible") && $(window).scrollTop() > 90){
if(!$(".top-button").is(":visible")){
$(".top-button").css('display', 'block');
}
}else{
$(".top-button").css('display', 'none');
}
});
$(window).on('load', function () {
// Project content
$.getJSON("settings.json", (data) => {
$.each(data["projects"], (key, val) => {
$("#project-section").prepend(project_factory(val));
});
$("#contact-section").append(contact_page_factory(data["contact"]));
$.each(data["landing"], (key, val) => {
// $("#landing-slides").append(slider_image_factory(val));
});
});
$("#nav-button--next").on("click", () => {
changeSlide(currentSlide + 1)
});
$("#nav-button--prev").on("click", () => {
changeSlide(currentSlide - 1)
});
display_section('landing-section');
$("#loader-wrapper").fadeOut(700);
});