added in typewriter effect to header
This commit is contained in:
parent
de9d40066c
commit
e7c045f9e2
2
dist/css/main.css
vendored
2
dist/css/main.css
vendored
File diff suppressed because one or more lines are too long
2
dist/index.html
vendored
2
dist/index.html
vendored
File diff suppressed because one or more lines are too long
2
dist/js/main.js
vendored
2
dist/js/main.js
vendored
@ -1 +1 @@
|
|||||||
window.onscroll=()=>{document.body.scrollTop>=150||document.documentElement.scrollTop>=150?document.querySelector("nav").classList.add("scrolled"):document.querySelector("nav").classList.remove("scrolled");let e="";document.querySelectorAll("section").forEach((l=>{const t=l.offsetTop;window.pageYOffset>=t-60&&(e=l.getAttribute("id"))})),document.querySelectorAll("nav ul li").forEach((l=>{l.firstChild.classList.remove("active"),l.firstChild.href.includes(e)&&""!==e?l.firstChild.classList.add("active"):""===e&&document.querySelector("nav ul li").firstChild.classList.add("active")}))};
|
const scrollLimit=150;window.onscroll=()=>{document.body.scrollTop>=150||document.documentElement.scrollTop>=150?document.querySelector("nav").classList.add("scrolled"):document.querySelector("nav").classList.remove("scrolled");let e="";document.querySelectorAll("section").forEach((t=>{const o=t.offsetTop;window.pageYOffset>=o-60&&(e=t.getAttribute("id"))})),document.querySelectorAll("nav ul li a").forEach((t=>{t.classList.remove("active"),t.href.includes(e)&&""!==e?t.classList.add("active"):""===e&&document.querySelector("nav ul li a").classList.add("active")}))},document.addEventListener("DOMContentLoaded",(()=>{var e=["full stack developer","web designer","student","gamer","drummer"];function t(e,o,n){o<e.length?(document.querySelector("header div h1").innerHTML=e.substring(0,o+1)+'<span aria-hidden="true">_</span>',setTimeout((function(){t(e,o+1,n)}),100)):"function"==typeof n&&setTimeout(n,700)}!function o(n){void 0===e[n]?setTimeout((function(){o(0)}),1e3):n<e[n].length&&t(e[n],0,(function(){o(n+1)}))}(0)}));
|
@ -190,6 +190,17 @@ i.fa-chevron-down {
|
|||||||
margin: 1.5rem 0;
|
margin: 1.5rem 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div h1 span {
|
||||||
|
visibility: visible;
|
||||||
|
animation: caret 1s steps(1) infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes caret {
|
||||||
|
50% {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 75em) {
|
@media screen and (max-width: 75em) {
|
||||||
nav {
|
nav {
|
||||||
display: block;
|
display: block;
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<div>
|
<div>
|
||||||
<h1>full stack developer_</h1>
|
<h1>full stack developer</h1>
|
||||||
<a href="" class="btn btnPrimary boxShadowIn boxShadowOut">Contact Me</a>
|
<a href="" class="btn btnPrimary boxShadowIn boxShadowOut">Contact Me</a>
|
||||||
<a href="#about"><i class="fas fa-chevron-down"></i></a>
|
<a href="#about"><i class="fas fa-chevron-down"></i></a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
// scrolling effect
|
||||||
|
const scrollLimit = 150;
|
||||||
window.onscroll = () =>
|
window.onscroll = () =>
|
||||||
{
|
{
|
||||||
if (document.body.scrollTop >= 150 || document.documentElement.scrollTop >= 150)
|
// check if scrolled past limit if so add scrolled class to change background of nav
|
||||||
|
if (document.body.scrollTop >= scrollLimit || document.documentElement.scrollTop >= scrollLimit)
|
||||||
{
|
{
|
||||||
document.querySelector("nav").classList.add("scrolled");
|
document.querySelector("nav").classList.add("scrolled");
|
||||||
}
|
}
|
||||||
@ -8,9 +11,9 @@ window.onscroll = () =>
|
|||||||
{
|
{
|
||||||
document.querySelector("nav").classList.remove("scrolled");
|
document.querySelector("nav").classList.remove("scrolled");
|
||||||
}
|
}
|
||||||
|
|
||||||
let current = "";
|
let current = ""; //id of current section scrolled to, set to "" if at top
|
||||||
|
// 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;
|
||||||
@ -19,17 +22,64 @@ window.onscroll = () =>
|
|||||||
current = section.getAttribute("id");
|
current = section.getAttribute("id");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelectorAll("nav ul li").forEach((li) =>
|
// go through all nav links, remove active class and add it to the link whose href matches the current id scrolled
|
||||||
|
// to
|
||||||
|
document.querySelectorAll("nav ul li a").forEach((a) =>
|
||||||
{
|
{
|
||||||
li.firstChild.classList.remove("active");
|
a.classList.remove("active");
|
||||||
if (li.firstChild.href.includes(current) && current !== "")
|
if (a.href.includes(current) && current !== "")
|
||||||
{
|
{
|
||||||
li.firstChild.classList.add("active");
|
a.classList.add("active");
|
||||||
}
|
}
|
||||||
else if (current === "")
|
else if (current === "")
|
||||||
{
|
{
|
||||||
document.querySelector("nav ul li").firstChild.classList.add("active");
|
document.querySelector("nav ul li a").classList.add("active"); // at the top
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', () =>
|
||||||
|
{
|
||||||
|
// array with texts to type in typewriter
|
||||||
|
var dataText = [ "full stack developer", "web designer", "student", "gamer", "drummer"];
|
||||||
|
|
||||||
|
// type one text in the typwriter
|
||||||
|
// keeps calling itself until the text is finished
|
||||||
|
function typeWriter(text, i, fnCallback) {
|
||||||
|
// chekc if text isn't finished yet
|
||||||
|
if (i < (text.length)) {
|
||||||
|
// 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
|
||||||
|
setTimeout(function() {
|
||||||
|
typeWriter(text, i + 1, fnCallback)
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
// text finished, call callback if there is a callback function
|
||||||
|
else if (typeof fnCallback == 'function') {
|
||||||
|
// 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() {
|
||||||
|
StartTextAnimation(0);
|
||||||
|
}, 1000);
|
||||||
|
// StartTextAnimation(0);
|
||||||
|
}
|
||||||
|
else if (i < dataText[i].length) {
|
||||||
|
// text exists! start typewriter animation
|
||||||
|
typeWriter(dataText[i], 0, function(){
|
||||||
|
// after callback (and whole text has been animated), start next text
|
||||||
|
StartTextAnimation(i + 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// start the text animation
|
||||||
|
StartTextAnimation(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user