2023-07-15 22:44:31 +00:00
|
|
|
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
2023-07-19 02:44:03 +00:00
|
|
|
const typeWriterSpeed = 60;
|
2023-07-15 22:44:31 +00:00
|
|
|
|
|
|
|
window.onload = function() {
|
|
|
|
document.querySelectorAll(".scramble").forEach(item => {
|
|
|
|
item.addEventListener("mouseover", scramble);
|
|
|
|
});
|
2023-07-18 03:17:11 +00:00
|
|
|
|
|
|
|
window.addEventListener('scroll', function() {
|
|
|
|
const parallax = document.querySelector('.parallax')
|
|
|
|
let scrollPosition = window.pageYOffset;
|
|
|
|
|
|
|
|
parallax.style.transform = 'translateY(' + scrollPosition * .5 + 'px)';
|
|
|
|
})
|
2023-07-19 02:44:03 +00:00
|
|
|
document.querySelectorAll(".typewriter").forEach(item => {
|
|
|
|
observer.observe(item);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function sleep(milliseconds) {
|
|
|
|
return new Promise(resolve => setTimeout(resolve, milliseconds));
|
2023-07-15 22:44:31 +00:00
|
|
|
}
|
|
|
|
|
2023-07-16 00:59:44 +00:00
|
|
|
function scramble(event){
|
|
|
|
scrambleLetters(event.target);
|
|
|
|
}
|
|
|
|
|
|
|
|
function scrambleLetters(element) {
|
2023-07-15 22:44:31 +00:00
|
|
|
let iterations = 0;
|
2023-07-16 00:59:44 +00:00
|
|
|
const originalValue = element.dataset.value;
|
2023-07-15 22:44:31 +00:00
|
|
|
|
|
|
|
let interval = setInterval(() => {
|
2023-07-16 00:59:44 +00:00
|
|
|
element.innerText = element.innerText.split("")
|
2023-07-15 22:44:31 +00:00
|
|
|
.map((letter, index) => {
|
|
|
|
if(index < iterations){
|
|
|
|
return originalValue[index];
|
|
|
|
}
|
|
|
|
return letters[Math.floor(Math.random() * letters.length)];
|
|
|
|
}).join("")
|
|
|
|
|
|
|
|
iterations += 1 / 3;
|
|
|
|
|
|
|
|
if(iterations > originalValue.length){
|
|
|
|
clearInterval(interval);
|
2023-07-16 00:59:44 +00:00
|
|
|
element.innerText = originalValue;
|
2023-07-15 22:44:31 +00:00
|
|
|
}
|
|
|
|
}, 30);
|
|
|
|
}
|
2023-07-16 00:59:44 +00:00
|
|
|
|
2023-07-19 02:44:03 +00:00
|
|
|
async function typeWriter(element) {
|
|
|
|
let typeWriterText = element.getAttribute("data-value");
|
|
|
|
let output = element.innerText;
|
|
|
|
|
|
|
|
for(let i = 0; i < typeWriterText.length; ++i){
|
|
|
|
output += typeWriterText.charAt(i);
|
|
|
|
// sleep for typeWriterSpeed milliseconds
|
|
|
|
await sleep(typeWriterSpeed);
|
|
|
|
element.innerText = output;
|
|
|
|
}
|
2023-07-16 00:59:44 +00:00
|
|
|
|
2023-07-19 02:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let observer = new IntersectionObserver(function(entries) {
|
|
|
|
for (let entry of entries){
|
|
|
|
// If the element is visible, start the animation
|
|
|
|
if(entry.isIntersecting) {
|
|
|
|
typeWriter(entry.target);
|
|
|
|
observer.unobserve(entry.target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, { threshold: 0.7 });
|