aktuelle.kurse/m152/x_gitressourcen/Animationen/Scroll-Animated Animations/scrollActivated.html

44 lines
1.2 KiB
HTML
Raw Normal View History

2021-06-25 16:17:59 +02:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scroll-Activated Animations</title>
</head>
<body>
<div>
<h1>Titel</h1>
<div id="hier"></div>
</div>
<script>
let generatedCount = 0;
let divElement = document.getElementById("hier");
document.addEventListener("scroll", doOnScroll);
function fillDocument() {
for (let index = 0; index < 100; index++) {
generatedCount++;
let newElement = document.createElement("h2");
newElement.innerHTML = `hallo ${generatedCount}`
divElement.appendChild(newElement);
}
}
function doOnScroll() {
if (window.innerHeight + window.scrollY + 500 > document.body.clientHeight) {
//console.log(`scrolled ${window.innerHeight} / ${window.scrollY} / ${document.body.clientHeight}`)
fillDocument();
}
}
fillDocument();
</script>
</body>
</html>