sound.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. playbksound();
  2. // Sound Control
  3. function $$(name) {
  4. return document.getElementById(name);
  5. }
  6. function switchsound() {
  7. au = $$('bgsound');
  8. ai = $$('sound_image');
  9. if (au.paused) {
  10. au.play();
  11. ai.src = "images/music.png";
  12. pop_up_note_mode = true;
  13. popup_note();
  14. $$("music_txt").innerHTML = "ON";
  15. $$("music_txt").style.visibility = "visible";
  16. setTimeout(function () { $$("music_txt").style.visibility = "hidden" }, 2500);
  17. }
  18. else {
  19. pop_up_note_mode = false;
  20. au.pause();
  21. ai.src = "images/music_off.png";
  22. $$("music_txt").innerHTML = "OFF";
  23. $$("music_txt").style.visibility = "visible";
  24. setTimeout(function () { $$("music_txt").style.visibility = "hidden" }, 2500);
  25. }
  26. }
  27. function playbksound() {
  28. var audiocontainer = $$('audiocontainer');
  29. if (audiocontainer != undefined) {
  30. audiocontainer.innerHTML = '<audio id="bgsound" loop="loop"> <source src="images/background.mp3" /> </audio>';
  31. }
  32. var audio = $$('bgsound');
  33. audio.play();
  34. sound_div = document.createElement("div");
  35. sound_div.setAttribute("ID", "cardsound");
  36. sound_div.style.cssText = "position:absolute;right:20px;top:14px;z-index:157;visibility:visible;";
  37. sound_div.onclick = switchsound;
  38. if (document.body.offsetWidth > 400) {
  39. bg_htm = "<img id='sound_image' width='40px' src='images/music.png'>";
  40. box_htm = "<div id='note_box' style='height:100px;width:44px;position:absolute;left:5px;top:-70px'></div>";
  41. txt_htm = "<div id='music_txt' style='color:#cccccc;font-size:16px;font-weight:bold;position:absolute;left:-40px;top:20px;width:60px'></div>"
  42. }
  43. else {
  44. bg_htm = "<img id='sound_image' width='40px' src='images/music_off.png'>";
  45. box_htm = "<div id='note_box' style='height:100px;width:44px;position:absolute;left:-5px;top:-80px'></div>";
  46. txt_htm = "<div id='music_txt' style='color:#cccccc;font-size:16px;font-weight:bold;position:absolute;left:-40px;top:10px;width:60px'></div>"
  47. }
  48. sound_div.innerHTML = bg_htm + box_htm + txt_htm;
  49. document.body.appendChild(sound_div);
  50. }
  51. //->