Home > Blockchain >  how to stop button play when click to play another button in elementor
how to stop button play when click to play another button in elementor

Time:07-02

im using wordpress with elementor i created multiple buttons that when clicked play a sound effect but my problem is when 1 button clicked and at the same time when button 1 playing if i clicked the button 2 also will play along side with button 1 how to make andy button to stop play when other is clicked ? *im using the following code to play button

<script>
$(document).ready(function() {
  //Audio 1 Starts
  var audio1 = new Audio('Sound-Effect-URL')
  $(".button-class").mousedown(function() {
    audio1.load();
    audio1.play();
  });
  //Audio 1 Ends
});
</script>```

CodePudding user response:

If you have both buttons code's on the same script you can try this:

<script>
$(document).ready(function() {
  //Audio 1 Starts
  var audio1 = new Audio('Sound-Effect-URL')
  var audio2 = new Audio('Sound-Effect-URL2')
  $(".button-class").mousedown(function() {

    audio2.pause();
    audio2.currentTime = 0;

    audio1.load();
    audio1.play();
  });
  //Audio 1 Ends
$(".button-class2").mousedown(function() {

    audio1.pause();
    audio1.currentTime = 0;

    audio2.load();
    audio2.play();
  });
});
</script>
  • Related