grant sykes
grant sykes

Reputation: 1

Pausing audio player when youtube video loads in Elementor

I have a client, I'm working in Elementor, I have a mp3 file I'm playing via var audio = document.getElementById("myaudio"); for background music, and I have a video in the header my client wants people to see when they click it. My issue, my background audio plays over my video.

I know I can use CSS classes to define the area to be clicked (gave it a class named headervideo), I have a pauseAudio() function that will pause the video, I'm just not code savy enough to make headervideo=pauseAudio() when clicked. I'm sure I need a addEventListener or something very simple like that, but I just cant quite wrap my brain around it.

Thank you for your time

Upvotes: 0

Views: 423

Answers (1)

JS KIM
JS KIM

Reputation: 695

I think you can do it this way.

var video = document.getElementById("yourVideo");
video.addEventListener('play', function() {
    audio.pause();
});

Upvotes: 1

Related Questions