|
1 | | -document.addEventListener("DOMContentLoaded", function() { |
2 | | - let elements = document.querySelectorAll(".slide-up"); |
3 | | - let observer = new IntersectionObserver(entries => { |
4 | | - entries.forEach(entry => { |
5 | | - if (entry.isIntersecting) { |
6 | | - entry.target.classList.add("visible"); |
| 1 | +document.addEventListener("DOMContentLoaded", () => { |
| 2 | + // Animasi scroll (fade-in saat di-scroll) |
| 3 | + const sections = document.querySelectorAll(".slide-up"); |
| 4 | + |
| 5 | + const scrollAnimation = () => { |
| 6 | + sections.forEach(section => { |
| 7 | + const sectionTop = section.getBoundingClientRect().top; |
| 8 | + const triggerPoint = window.innerHeight * 0.8; |
| 9 | + |
| 10 | + if (sectionTop < triggerPoint) { |
| 11 | + section.classList.add("visible"); |
7 | 12 | } |
8 | 13 | }); |
9 | | - }, { threshold: 0.5 }); |
10 | | - elements.forEach(el => observer.observe(el)); |
| 14 | + }; |
| 15 | + |
| 16 | + window.addEventListener("scroll", scrollAnimation); |
| 17 | + scrollAnimation(); // Jalankan sekali di awal untuk memeriksa posisi awal |
| 18 | + |
| 19 | + // Animasi hover di navigasi |
| 20 | + const navLinks = document.querySelectorAll("nav ul li a"); |
| 21 | + |
| 22 | + navLinks.forEach(link => { |
| 23 | + link.addEventListener("mouseover", () => { |
| 24 | + link.style.transform = "scale(1.2)"; |
| 25 | + link.style.transition = "transform 0.3s ease"; |
| 26 | + }); |
| 27 | + |
| 28 | + link.addEventListener("mouseout", () => { |
| 29 | + link.style.transform = "scale(1)"; |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + // Efek ketik otomatis di header |
| 34 | + const typingText = document.querySelector("header p"); |
| 35 | + const words = ["Mahasiswa Teknik Informatika", "Web Developer", "Tech Enthusiast"]; |
| 36 | + |
| 37 | + let wordIndex = 0; |
| 38 | + let charIndex = 0; |
| 39 | + |
| 40 | + const typeEffect = () => { |
| 41 | + if (charIndex < words[wordIndex].length) { |
| 42 | + typingText.textContent += words[wordIndex].charAt(charIndex); |
| 43 | + charIndex++; |
| 44 | + setTimeout(typeEffect, 100); |
| 45 | + } else { |
| 46 | + setTimeout(() => eraseEffect(), 1500); |
| 47 | + } |
| 48 | + }; |
| 49 | + |
| 50 | + const eraseEffect = () => { |
| 51 | + if (charIndex > 0) { |
| 52 | + typingText.textContent = words[wordIndex].substring(0, charIndex - 1); |
| 53 | + charIndex--; |
| 54 | + setTimeout(eraseEffect, 50); |
| 55 | + } else { |
| 56 | + wordIndex = (wordIndex + 1) % words.length; |
| 57 | + setTimeout(typeEffect, 500); |
| 58 | + } |
| 59 | + }; |
| 60 | + |
| 61 | + typeEffect(); |
11 | 62 | }); |
| 63 | + |
0 commit comments