Как остановить звук, когда я нажимаю на другое изображение? ⇐ CSS

Разбираемся в CSS
Anonymous
Как остановить звук, когда я нажимаю на другое изображение?

Сообщение Anonymous »


I want to play audio when I click to image. But when I click another image are playing both. I need to stop or pause first sound to play the new sound.

I don't want to use tag in html as soon as possible; not for something special just to get the challenge.

I am trying this:
HTML:
Изображение

Изображение

Изображение

Изображение

Изображение

Изображение
Javascript: window.addEventListener('load', function () { let images = document.querySelectorAll("img"); images.forEach(image =>{ image.addEventListener("click", playAudio); }) }, false); function playAudio (event){ let imgName = event.currentTarget.id; let audioPlay = new Audio(`./sounds/${imgName}.wav`); audioPlay.onloadedmetadata = function (eSound){ eSound.currentTarget.loop = true; eSound.currentTarget.play() } console.log(event) }

Источник: https://stackoverflow.com/questions/781 ... ther-image

Вернуться в «CSS»