Stop video from slider when slide to a new slider


Mon Jan 17 2022 12:42:40 GMT+0000 (UTC)

Saved by @kevinazoulay #javascript

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

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