Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

284
Views
Cuando hago clic en el botón, no hay efecto de sonido.

Quería volver a preguntar, basándome en la respuesta que obtuve a una pregunta que había hecho antes. Estoy tratando de hacer un efecto de sonido cuando se hace clic en los botones de mi proyecto. Vi que el efecto de sonido que le di dirección a los botones no se materializó. Luego concluí como publiqué a continuación. Pero esto no funciona del todo bien.

 <button href="index.html" type="button" class="menu-icon" onClick="playMyAudio()" preload="auto">Play Audio</button> <audio src="sound/Message Pop.mp3" preload="auto" id="myAudio"></audio> <script> const audioEl = document.getElementById("myAudio"); function playMyAudio() { audioEl.play(); } const buttonLinks = document.querySelectorAll("button[href]"); const delay = 75;//milliseconds audioEl.addEventListener("canplaythrough", () => { buttonLinks.forEach(btn => { btn.addEventListener("click", (e) => { setTimeout(() => { window.location = btn.getAttribute("href") }, audioEl.duration + delay); }) }); }); </script>

¿Qué método puedo seguir para un resultado más efectivo aquí?

En la versión final, los botones a veces suenan ya veces no.

Gracias.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Aquí hay un ejemplo que armé de hacer clic en un botón para reproducir un MP3 en Javascript. ¡Espero que esto ayude!

aplicación.html

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Sound Test</title> </head> <body> <button id="soundButton">Click Me!</button> <script type="text/javascript" src="app.js"></script> </body> </html>

aplicación.js

 const soundButton = document.querySelector('#soundButton'); soundButton.addEventListener('click', function () { playSound(); }); function playSound() { const sound = new Audio('catMeowing.mp3').play(); }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!