Files
RTA-test/script.js

27 lines
943 B
JavaScript
Raw Normal View History

2025-01-25 21:25:36 +01:00
window.onload = function() {
2025-01-25 21:45:48 +01:00
// Select all paragraphs that immediately follow an h2 element
2025-01-25 21:25:36 +01:00
const articles = document.querySelectorAll('h2 + p');
articles.forEach((article, index) => {
2025-01-25 21:45:48 +01:00
// Set initial opacity of each article to 0 (hidden)
2025-01-25 21:25:36 +01:00
article.style.opacity = '0';
2025-01-25 21:45:48 +01:00
// Function to gradually increase the opacity of the article
2025-01-25 21:25:36 +01:00
const fadeIn = () => {
let opacity = 0;
const increaseOpacity = () => {
2025-01-25 21:25:36 +01:00
opacity += 0.05;
article.style.opacity = opacity;
// Continue the animation until opacity reaches 1 (fully visible)
if (opacity < 1) {
requestAnimationFrame(increaseOpacity);
2025-01-25 21:25:36 +01:00
}
};
requestAnimationFrame(increaseOpacity);
2025-01-25 21:25:36 +01:00
};
2025-01-25 21:45:48 +01:00
// Delay the fade-in effect based on the article's index
setTimeout(fadeIn, 500 * index);
2025-01-25 21:25:36 +01:00
});
};