Stop video from slider when slide to a new slider

PHOTO EMBED

Mon Jan 17 2022 12:42:40 GMT+0000 (Coordinated Universal Time)

Saved by @kevinazoulay #javascript

<script>
$(function() {
    var observer = new MutationObserver(function (mutations) {
        for(let mutation of mutations) {
            setTimeout(function() {
                if(mutation.oldValue || mutation.target.getAttribute('aria-hidden') != 'true')
                    return;
                let player = $(mutation.target).find('iframe').get(0);
                player.src += '';
            }, 500);
        }
    });
    $('.slide.w-slide').each(function () {
        observer.observe(this, {
            attributes: true,
            attributeFilter: ['aria-hidden'],
            attributeOldValue : true
        });
    })
});
</script>
content_copyCOPY

The outer function inside $(); makes sure the code runs after the entire page was loaded The observer is a MutationObserver, which can detect when an HTML element's attribute has changed. when the correct one has changed (aria-hidden), run the code to reset the youtube video Let Player: This gets the iframe element and with a trick, it reloads the "src" attribute