-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
128 lines (100 loc) · 3.43 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
// circle skill
const circles = document.querySelectorAll(".circle");
circles.forEach((elem) => {
var dots = elem.getAttribute("data-dots");
var marked = elem.getAttribute("data-percent");
var percent = Math.floor((dots * marked) / 100);
var points = "";
var rotate = 360 / dots;
for (let i = 0; i < dots; i++) {
points += `<div class="points" style="--i:${i}; --rot:${rotate}deg"></div>`;
}
elem.innerHTML = points;
const pointsMarked = elem.querySelectorAll(".points");
for (let i = 0; i < percent; i++) {
pointsMarked[i].classList.add("marked");
}
});
// mix it up portfolio section
var mixer = mixitup(".portfolio-gallery");
//active menu
let menuLi = document.querySelectorAll("header ul li a");
let section = document.querySelectorAll("section");
function activeMenu() {
let len = section.length;
while (--len && window.scrollY + 97 < section[len].offsetTop) {}
menuLi.forEach((sec) => sec.classList.remove("active"));
menuLi[len].classList.add("active");
}
activeMenu();
window.addEventListener("scroll", activeMenu);
// sticky navbar
const header = document.querySelector("header");
window.addEventListener("scroll", function () {
header.classList.toggle("sticky", window.scrollY > 50);
});
// form submission
window.addEventListener("DOMContentLoaded", function () {
// get the form elements defined in your form HTML above
var form = document.getElementById("my-form");
// var button = document.getElementById("my-form-button");
var status = document.getElementById("status");
// Success and Error functions for after the form is submitted
function success() {
form.reset();
status.classList.add("success");
status.innerHTML = "Thanks! Submitted successfully";
}
function error() {
status.classList.add("error");
status.innerHTML = "Oops! There was a problem.";
}
// handle the form submission event
form.addEventListener("submit", function (ev) {
ev.preventDefault();
var data = new FormData(form);
ajax(form.method, form.action, data, success, error);
});
});
// helper function for sending an AJAX request
function ajax(method, url, data, success, error) {
var xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.setRequestHeader("Accept", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState !== XMLHttpRequest.DONE) return;
if (xhr.status === 200) {
success(xhr.response, xhr.responseType);
} else {
error(xhr.status, xhr.response, xhr.responseType);
}
};
xhr.send(data);
}
// toggle icon navbar
let menuIcon = document.querySelector("#menu-icon");
let navlist = document.querySelector(".navlist");
menuIcon.onclick = () => {
menuIcon.classList.toggle("bx-x");
navlist.classList.toggle("open");
};
window.onscroll = () => {
menuIcon.classList.remove("bx-x");
navlist.classList.remove("open");
};
// parallax
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("show-items");
} else {
entry.target.classList.remove("show-items");
}
});
});
const scrollScale = document.querySelectorAll(".scroll-scale");
scrollScale.forEach((el) => observer.observe(el));
const scrollBottom = document.querySelectorAll(".scroll-bottom");
scrollBottom.forEach((el) => observer.observe(el));
const scrollTop = document.querySelectorAll(".scroll-top");
scrollTop.forEach((el) => observer.observe(el));