forked from shooft/FED24-25
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b564b8
commit 99512ea
Showing
1 changed file
with
14 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,48 @@ | ||
// Code voor de rollover van 2 tekst lines op de homepage. | ||
// Bron: beetje hulp van ChatGPT | ||
|
||
document.addEventListener("DOMContentLoaded", function () { | ||
// Calculate initial translateX values | ||
// standaard posities | ||
const initialTranslateX1 = -250; | ||
const initialTranslateX2 = -130; | ||
|
||
// Get references to the elements | ||
const rolloverTextWrap = document.querySelector('.rollover-text-wrap'); | ||
const rolloverTextElements = document.querySelectorAll('.rollover-text'); | ||
|
||
// Function to update the transform property of rollover-text elements | ||
// op bsis van de scrollprogress, beide teksten op de x axis bewegen | ||
function updateTransform(scrollProgress) { | ||
//beide x translations gaan andere kant op d.m.v. "-" & "+" | ||
const translateX1 = initialTranslateX1 - scrollProgress * 150; | ||
const translateX2 = initialTranslateX2 + scrollProgress * 150; | ||
|
||
|
||
// translation values toepassen | ||
rolloverTextElements[0].style.transform = `translateX(${translateX1}px)`; | ||
rolloverTextElements[1].style.transform = `translateX(${translateX2}px)`; | ||
} | ||
|
||
// Options for the Intersection Observer | ||
// intersection observer options | ||
const observerOptions = { | ||
threshold: [0, 1], // Trigger the observer when the element enters or exits the viewport | ||
threshold: [0, 1], // begin als het hele element is de viewport is en eindig als het helemaal buiten is | ||
}; | ||
|
||
// Create an Intersection Observer | ||
// intersection observer | ||
const observer = new IntersectionObserver((entries) => { | ||
const entry = entries[0]; | ||
const scrollProgress = entry.intersectionRatio; // Use intersectionRatio directly | ||
const scrollProgress = entry.intersectionRatio; // intersectionRatio gebruiken voor de scrollProgress | ||
updateTransform(scrollProgress); | ||
}, observerOptions); | ||
|
||
// Observe the rolloverTextWrap element | ||
// rollover tekst observen | ||
observer.observe(rolloverTextWrap); | ||
|
||
// Attach scroll event listener | ||
// scroll listener maken | ||
window.addEventListener('scroll', () => { | ||
const scrollPosition = rolloverTextWrap.getBoundingClientRect().bottom / window.innerHeight; | ||
// Ensure scroll progress is between 0 and 1 | ||
const scrollProgress = Math.min(Math.max(scrollPosition, 0), 1); | ||
updateTransform(scrollProgress); | ||
}); | ||
|
||
// Initial update of the transform based on scroll position | ||
// eerste update van de transform op basis van scrollpositie | ||
window.dispatchEvent(new Event('scroll')); | ||
}); | ||
|
||
|