Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
How do I get an audio snippet to play when hovering over an image element?

After too many hours on YT and Google, I'm here. Thanks for taking the time to read & help. :)

I'm trying to make it so that when the mouse hovers over the image, an audio snippet plays automatically. I've tried a few different things, but this is where I stopped. Can't seem to get anything to work.

HTML file snippet

<head>
    <link rel="stylesheet" href="./stylesheet.css">
    <script type="text/javascript" src="./scripts.js"></script>
...other stuff etc etc


<div class="deviruchi" data-tooltip="no touchy!">
<audio id="devi">

    <source src="./sounds/deviruchi_idle.mp3">
    <source src="./sounds/deviruchi_idle.ogg">

</audio>

        <img src="./images/deviruchi.gif">

        </div> 

Javascript file

let deviruchi = $("#devi")[0];
$(".deviruchi").onmouseenter(function () {
    deviruchi.play();
});

Thanks again! :)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Probably because you are using jquery...(j/k, but no really)

Make sure that the audio files are present on the server, check devtools for error messages (javascript as well as network) Also, user must first interact with the webpage (click/focus, etc) before browser will allow play media files.

hoverMe.addEventListener("mouseenter", e =>
{
  myAudio.play().catch(er => console.error(er.message, "Now, click here and try again"));
});

hoverMe.addEventListener("mouseleave", e =>
{
  myAudio.pause();
});
<div id="hoverMe">Hover over here</div>
<audio id="myAudio" src="https://sample-videos.com/audio/mp3/crowd-cheering.mp3"></audio>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda