Created CV Section #6

Merged
rodude123 merged 17 commits from cv into master 2021-08-31 18:53:13 +01:00
Showing only changes of commit 5e2d42b409 - Show all commits

View File

@ -2,84 +2,94 @@
const scrollLimit = 150; const scrollLimit = 150;
window.onscroll = () => window.onscroll = () =>
{ {
// check if scrolled past limit if so add scrolled class to change background of nav // check if scrolled past limit if so add scrolled class to change background of nav
if (document.body.scrollTop >= scrollLimit || document.documentElement.scrollTop >= scrollLimit) if (document.body.scrollTop >= scrollLimit || document.documentElement.scrollTop >= scrollLimit)
{ {
document.querySelector("nav").classList.add("scrolled"); document.querySelector("nav").classList.add("scrolled");
} }
else else
{ {
document.querySelector("nav").classList.remove("scrolled"); document.querySelector("nav").classList.remove("scrolled");
} }
let current = ""; //id of current section scrolled to, set to "" if at top let current = ""; //id of current section scrolled to, set to "" if at top
// go through all sections and find current section id scrolled to // go through all sections and find current section id scrolled to
document.querySelectorAll("section").forEach((section) => document.querySelectorAll("section").forEach((section) =>
{ {
const sectionTop = section.offsetTop; const sectionTop = section.offsetTop;
if (window.pageYOffset >= sectionTop - 60) if (window.pageYOffset >= sectionTop - 60)
{ {
current = section.getAttribute("id"); current = section.getAttribute("id");
} }
}); });
// go through all nav links, remove active class and add it to the link whose href matches the current id scrolled // go through all nav links, remove active class and add it to the link whose href matches the current id scrolled
// to // to
document.querySelectorAll("nav ul li a").forEach((a) => document.querySelectorAll("nav ul li a").forEach((a) =>
{ {
a.classList.remove("active"); a.classList.remove("active");
if (a.href.includes(current) && current !== "") if (a.href.includes(current) && current !== "")
{ {
a.classList.add("active"); a.classList.add("active");
} }
else if (current === "") else if (current === "")
{ {
document.querySelector("nav ul li a").classList.add("active"); // at the top document.querySelector("nav ul li a").classList.add("active"); // at the top
} }
}); });
}; };
document.addEventListener('DOMContentLoaded', () => document.addEventListener("DOMContentLoaded", () =>
{ {
// array with texts to type in typewriter // array with texts to type in typewriter
var dataText = [ "full stack developer", "web designer", "student", "gamer", "drummer"]; var dataText = ["full stack developer", "web designer", "student", "gamer", "drummer"];
// type one text in the typwriter // type one text in the typwriter
// keeps calling itself until the text is finished // keeps calling itself until the text is finished
function typeWriter(text, i, fnCallback) { function typeWriter(text, i, fnCallback)
// chekc if text isn't finished yet {
if (i < (text.length)) { // chekc if text isn't finished yet
// add next character to h1 if (i < (text.length))
document.querySelector("header div h1").innerHTML = text.substring(0, i+1) +'<span aria-hidden="true">_</span>'; {
// add next character to h1
document.querySelector("header div h1").innerHTML = text.substring(0, i + 1) + "<span aria-hidden=\"true\">_</span>";
// wait for a while and call this function again for next character // wait for a while and call this function again for next character
setTimeout(function() { setTimeout(function ()
typeWriter(text, i + 1, fnCallback) {
}, 100); typeWriter(text, i + 1, fnCallback)
} }, 100);
// text finished, call callback if there is a callback function }
else if (typeof fnCallback == 'function') { // text finished, call callback if there is a callback function
// call callback after timeout else if (typeof fnCallback == "function")
setTimeout(fnCallback, 700); {
} // call callback after timeout
} setTimeout(fnCallback, 700);
// start a typewriter animation for a text in the dataText array }
function StartTextAnimation(i) { }
if (typeof dataText[i] === 'undefined'){
setTimeout(function() { // start a typewriter animation for a text in the dataText array
StartTextAnimation(0); function StartTextAnimation(i)
}, 1500); {
// StartTextAnimation(0); if (typeof dataText[i] === "undefined")
} {
else if (i < dataText[i].length) { setTimeout(function ()
// text exists! start typewriter animation {
typeWriter(dataText[i], 0, function(){ StartTextAnimation(0);
// after callback (and whole text has been animated), start next text }, 1500);
setTimeout(StartTextAnimation, 1500, i + 1); }
}); else if (i < dataText[i].length)
} {
} // text exists! start typewriter animation
// start the text animation typeWriter(dataText[i], 0, function ()
StartTextAnimation(0); {
// after callback (and whole text has been animated), start next text
setTimeout(StartTextAnimation, 1500, i + 1);
});
}
}
// start the text animation
StartTextAnimation(0);
}); });