Advertisement
ukamori

mouse click sfx

Aug 11th, 2022
3,387
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.  
  3. // Mouseover/ Click sound effect- by JavaScript Kit (www.javascriptkit.com)
  4. // Visit JavaScript Kit at http://www.javascriptkit.com/ for full source code
  5.  
  6. //** Usage: Instantiate script by calling: var uniquevar=createsoundbite("soundfile1", "fallbackfile2", "fallebacksound3", etc)
  7. //** Call: uniquevar.playclip() to play sound
  8.  
  9. var html5_audiotypes={ //define list of audio file extensions and their associated audio types. Add to it if your specified audio file isn't on this list:
  10. "mp3": "audio/mpeg",
  11. "mp4": "audio/mp4",
  12. "ogg": "audio/ogg",
  13. "wav": "audio/wav"
  14. }
  15.  
  16. function createsoundbite(sound){
  17. var html5audio=document.createElement('audio')
  18. if (html5audio.canPlayType){ //check support for HTML5 audio
  19. for (var i=0; i<arguments.length; i++){
  20. var sourceel=document.createElement('source')
  21. sourceel.setAttribute('src', arguments[i])
  22. if (arguments[i].match(/\.(\w+)$/i))
  23. sourceel.setAttribute('type', html5_audiotypes[RegExp.$1])
  24. html5audio.appendChild(sourceel)
  25. }
  26. html5audio.load()
  27. html5audio.playclip=function(){
  28. html5audio.pause()
  29. html5audio.currentTime=0
  30. html5audio.play()
  31. }
  32. return html5audio
  33. }
  34. else{
  35. return {playclip:function(){throw new Error("Your browser doesn't support HTML5 audio unfortunately")}}
  36. }
  37. }
  38.  
  39. //Initialize two sound clips with 1 fallback file each:
  40.  
  41. var mouseoversound=createsoundbite("https://cdn.discordapp.com/attachments/916511538410569829/1006909357981712414/mouse_click_fx.mp3")
  42. var clicksound=createsoundbite("https://cdn.discordapp.com/attachments/916511538410569829/1006909357981712414/mouse_click_fx.mp3")
  43.  
  44. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement