-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
95 lines (74 loc) · 2.84 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
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
$(function(){
var pages = $(".page");
var header = $("header");
$(".span-letters").each(function(){
let elem = $(this);
let textArray = elem.text().split(""); //Split each letter
elem.html("");
for(let i in textArray){
elem.append("<span class='letter'" + (textArray[i] == " " ? " style='width: 0.3em;'" : "") + ">" + textArray[i] + "</span>");
}
});
$("[data-page]").click(function(event){
event.preventDefault();
let targetPage = $("#" + $(this).data("page"));
//Animate the scroll
$("html, body").animate({
scrollTop: targetPage.offset().top - parseInt(targetPage.css("marginTop").replace("px", "")) - header.height() // - parseInt(targetPage.css("paddingTop"))
}, 750);
//Close the nav menu
$("nav").removeClass("active");
});
var slider = $(".nav-active-slider");
function onScroll(){
var windowTop = $(window).scrollTop() + header.height();
for(let i = pages.length - 1; i >= 0; i--){ //Start at the bottom first so we only have to check the top of pages
let page = pages.eq(i);
let pageTop = page.offset().top;
let pageHeight = page.height();
if(pageTop < windowTop + (pageHeight * 0.3)){ //If most of the page is in view
let pageNavItem = $("nav a[data-page='" + page.attr("id") + "']");
let pageColor = page.css("border-color");
if(pageNavItem.length > 0){
slider.css({
left: pageNavItem.position().left,
width: pageNavItem.width(),
"background-color": pageColor
});
}
header.find("h1").css("border-bottom-color", pageColor);
break;
}
}
}
$(document).scroll(onScroll);
onScroll();
//Masonry imagesLoaded
$("[data-masonry]").each(function(){
let grid = $(this);
grid.imagesLoaded().progress(function(){
grid.masonry();
});
//Make all images zoomable
grid.find("img").attr("data-action", "zoom");
});
$(".tab-title").click(function(){
let title = $(this);
let item = title.closest(".tab-item");
let content = title.siblings(".tab-content");
if(item.hasClass("expanded")){
item.removeClass("expanded");
content.slideUp(250);
// setTimeout(() => content.slideUp(500), 1000);
} else {
item.siblings(".tab-item.expanded").removeClass("expanded").find(".tab-content").slideUp(250);
item.addClass("expanded");
content.slideDown(250);
}
});
});
function toggleNav(elem){
elem = $(elem);
// elem.toggleClass("active");
$("nav").toggleClass("active");
}