custom - Bloc 3

Derniers cours : custom

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();
}
});

Condition if exists sur shortcode ACF

Condition if exists sur shortcode ACF

Je trouve très utile avec les ACF de pouvoir facilement vérifier si une variable existe avant de l'afficher, seule ou englobée dans du code. Cette fonction PHP permet d'utiliser cette condition au moyen de [shortcodes]
				
					// mettre des conditions sur les shortcodes ACF https://support.advancedcustomfields.com/forums/topic/conditional-shortcodes/
// [acfcond field='']foobar[/acfcond]
function acfcond($atts = [], $content = null)
{
    $atts = array_change_key_case((array)$atts, CASE_LOWER);

    if(get_field($atts['field']))
    {
        $content = do_shortcode($content);
    }
    else
    {
        $content = '';
    }

    return $content;
}
add_shortcode('acfcond', 'acfcond');
				
			

Du coup dans Elementor on peut faire

				
					[acfcond field='le_mot_du_directeur']
<h2>Le mot du directeur (shortcode)</h2>

[/acfcond]