Files
RTA-test/script.js

26 lines
893 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 => {
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 interval = setInterval(() => {
opacity += 0.05;
article.style.opacity = opacity;
2025-01-25 21:45:48 +01:00
// Stop the interval when opacity reaches 1 (fully visible)
2025-01-25 21:25:36 +01:00
if (opacity >= 1) {
clearInterval(interval);
}
}, 30);
};
2025-01-25 21:45:48 +01:00
// Delay the fade-in effect based on the article's index
2025-01-25 21:25:36 +01:00
setTimeout(fadeIn, 500 * articles.indexOf(article));
});
};