Advertisement
powylv

sound effect on click

Oct 21st, 2022 (edited)
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. // Click Sound Effect by JavaScript Kit (http://www.javascriptkit.com)
  3.  
  4. var html5_audiotypes={
  5. "mp3": "audio/mpeg",
  6. "mp4": "audio/mp4",
  7. "ogg": "audio/ogg",
  8. "wav": "audio/wav"
  9. }
  10.  
  11. function createsoundbite(sound){
  12. var html5audio=document.createElement('audio')
  13. if (html5audio.canPlayType){
  14. for (var i=0; i<arguments.length; i++){
  15. var sourceel=document.createElement('source')
  16. sourceel.setAttribute('src', arguments[i])
  17. if (arguments[i].match(/\.(\w+)$/i))
  18. sourceel.setAttribute('type', html5_audiotypes[RegExp.$1])
  19. html5audio.appendChild(sourceel)
  20. }
  21.  
  22. html5audio.load()
  23. html5audio.playclip=function(){
  24. html5audio.pause()
  25. html5audio.currentTime=0
  26. html5audio.play()
  27. }
  28.  
  29. return html5audio
  30. }
  31. else{
  32. return {playclip:function(){}}
  33. }
  34. }
  35.  
  36. var clicksound=createsoundbite("https://dl.dropbox.com/s/79xiksac40a2i65/interfaceclick.wav")
  37. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement