-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·107 lines (87 loc) · 2.94 KB
/
script.js
File metadata and controls
executable file
·107 lines (87 loc) · 2.94 KB
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
// Store objects in variables
var sideBar = document.getElementById("sideBar");
var openBtn = document.getElementById("openBtn");
var header = document.getElementById("header");
var goToTop = document.getElementById("goToTop");
var openPopup = document.getElementById("openPopup");
var popUp = document.getElementById("popUp");
var overlay = document.getElementById("overlay");
var closePopup = document.getElementById("closePopup");
// Add the event listener
openBtn.addEventListener("click", openSidebar);
openPopup.addEventListener("click", openPopupOverlay);
overlay.addEventListener("click", closePopupOverlay);
closePopup.addEventListener("click", closePopupOverlay);
// Function to react to the event listener
function openSidebar() {
// Toggle the class name on the element
sideBar.classList.toggle("open");
openBtn.classList.toggle("open");
}
// Function to show the overlay and popup
function openPopupOverlay() {
popUp.classList.add("showPopup");
overlay.classList.add("showOverlay");
}
function closePopupOverlay() {
popUp.classList.remove("showPopup");
overlay.classList.remove("showOverlay");
}
// Attach a listener to the window
window.onscroll = function(e) {
// Get the pageYOffset
var pageOffset = window.pageYOffset;
// Get the page total height
var pageTotalHeight = document.body.clientHeight;
var pageTotalWidth = document.body.clientWidth;
// Page height minus the browser height
var totalHeightMinusBrowser = document.body.clientHeight -window.innerHeight;
var heightDifference = 20;
// Check for Browser Width
if ( pageTotalWidth < 500 ) {
heightDifference = 20;
} else {
heightDifference = -280;
}
// Deduct the difference
totalHeightMinusBrowser -= heightDifference;
// If the offset is more than 200
if ( pageOffset > 200 ) {
// Add the class name
header.classList.add("collapsed");
// If the offset is less than 200
} else {
// Remove the class name
header.classList.remove("collapsed");
};
// Bottom of the page
if ( pageOffset > totalHeightMinusBrowser ) {
goToTop.classList.add("active");
} else {
goToTop.classList.remove("active");
};
};
/*+++++++++++++++++++++++++*/
// Animate scrolling with jQuery
// https://css-tricks.com/snippets/jquery/smooth-scrolling/
var headerOffset = 130;
$(function() {
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
console.log(target.selector);
if ( target.selector == "#manifesto") {
headerOffset = 300;
}else{
headerOffset = 130;
};
$('html, body').animate({
scrollTop: target.offset().top - headerOffset
}, 1000);
return false;
}
}
});
});