septembre 15, 2023 - Bloc 3

Derniers cours : septembre 15, 2023

Les cours sont classés par ordre où ils ont été donnés, du plus récent au plus ancien.

Fonction jQuery pour lancer une fonction lors de l’entrée d’un élément dans le viewport

// Function to run the jQuery animation
function runAnimation() {
$("#elementToAnimate").animate({
opacity: 1,
top: 0
}, 1000); // 1000 milliseconds = 1 second
}

// Function to check if the element is in the viewport
function isElementInViewport(element) {
var windowTop = $(window).scrollTop();
var elementTop = $(element).offset().top;
var elementBottom = elementTop + $(element).outerHeight();

return elementBottom > windowTop && elementTop < windowTop + $(window).height();
}

// Check if the element is initially in the viewport
if (isElementInViewport("#elementToAnimate")) {
runAnimation();
}

// Check if the element enters the viewport when scrolling
$(window).on("scroll", function () {
if (isElementInViewport("#elementToAnimate")) {
runAnimation();
}
});