Make HTML5 and iFrame videos stop and rewind when Badger Accordion tab closed
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I'm using Badger Accordion. Some tabs have videos (html5, youtube, vimeo). If someone is play a video in an open accordion and then goes to another accordion (which would close the current) I need that video to stop/rewind.

I have a solution working for modals but can't figure it out for badger accordion. I see there is a badger.close()

Here is my current script:


import BadgerAccordion from 'badger-accordion';
// MULTI ON PAGE
const accordions = document.querySelectorAll('.js-badger-accordion');
Array.from(accordions).forEach((accordion) => {
const ba = new BadgerAccordion(accordion);
// I THINK IT GOES HERE
});

And here is what I used for my modals that is working exactly how I want this to just as an example. You can see they have an "onClose to work with (using micro modal):

onClose: modal => {
modal.querySelectorAll('.d3-vids').forEach(iframe => {
iframe.setAttribute('src', iframe.getAttribute('src'));
});
modal.querySelectorAll('.d3-vids').forEach(video => {
video.setAttribute('src', video.getAttribute('src'));
});

Here it's working for iframe src's...buttttt it uses jQuery. Can someone please help me get this without using jQUERY?

$(".badger-accordion__trigger").click(function () {

$('.d3-vid').each(function () {

$(this).attr('src', $(this).attr('src'));

return false;

});

});

THANK YOU!

i recommend reloading iframes once accordion is closed.
Chlegou 4 months ago
4 months ago
Tags
javascript

Crowdsource coding tasks.

0 Solutions