Advertisement
Guest User

Untitled

a guest
May 5th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.93 KB | None | 0 0
  1.  
  2. <section id="spillBG">
  3. <section id="bokser">
  4. <div id="ganesha">
  5. <div class="circle"></div>
  6. <%= audio_tag "ganesha.m4a", id: 'ganeshaLyd'%>
  7. </div>
  8. <div id="vibhuti">
  9. <div class="circle"></div>
  10. <%= audio_tag "vibhuti.m4a", id: 'vibhutiLyd'%>
  11. </div>
  12. <div id="rokelse">
  13. <div class="circle"></div>
  14. <%= audio_tag "rokelse.m4a", id: 'rokelseLyd'%>
  15. </div>
  16. <div id="blomster">
  17. <div class="circle"></div>
  18. <%= audio_tag "blomster.m4a", id: 'blomsterLyd'%>
  19. </div>
  20. <div id="offer">
  21. <div class="circle"></div>
  22. <%= audio_tag "offer.m4a", id: 'offerLyd'%>
  23. </div>
  24. <div id="info">
  25. <p>Test deg selv</p>
  26. </div>
  27. <div id="draggable">
  28. <p class="navn ganesha" data-navn="ganesha">Ganesha</p>
  29. <p class="navn vibhuti" data-navn="vibhuti">Vibhuti</p>
  30. <p class="navn rokelse" data-navn="rokelse">Røkelse</p>
  31. <p class="navn blomster" data-navn="blomster">Blomster</p>
  32. <p class="navn offer" data-navn="offer">Offer</p>
  33. </div>
  34. </section>
  35. </section>
  36. <script>
  37. $(function() {
  38. var antRiktige = 0;
  39. var antFeil = 0;
  40.  
  41.  
  42.  
  43. function stilSettStart() {
  44. $(".ganesha").css({
  45. "top": 135 + "px",
  46. "left": 420 + "px",
  47. "positon":"absolute"
  48. });
  49. $(".vibhuti").css({
  50. "top": 320 + "px",
  51. "left": 260 + "px"
  52. });
  53. $(".rokelse").css({
  54. "top": 370 + "px",
  55. "left": 590 + "px"
  56. });
  57. $(".blomster").css({
  58. "top": 207 + "px",
  59. "left": 420 + "px"
  60. });
  61. $(".offer").css({
  62. "top": 335 + "px",
  63. "left": 420 + "px"
  64. });
  65. $(".navn").css("position", "absolute");
  66.  
  67. }
  68.  
  69. function settEvents() {
  70. //LYDEVENT
  71. $(".circle").on("click", function() {
  72. var parentsId = $(this).parent().attr("id");
  73. $("." + parentsId).toggle();
  74. if ($("." + parentsId).is(":visible")) {
  75. var audio = $("#" + parentsId + "Lyd")[0];
  76. audio.play();
  77. }
  78.  
  79. });
  80.  
  81.  
  82. $("#info p").on("click", function() {
  83.  
  84. if(antRiktige == 5) {
  85. stilSettStart();
  86. $("#draggable").css("position","static");
  87. $("#draggable p").css({
  88. "background-color":"white",
  89. "display":"none"
  90. });
  91.  
  92. antRiktige = 0;
  93. antFeil = 0;
  94.  
  95. $("#draggable p").draggable('enable');
  96. $("#draggable p").draggable('option', 'revert', true);
  97. $("#info p").html("Test deg selv");
  98. $(".circle").css("background-color","transparent");
  99.  
  100.  
  101.  
  102. $(".circle").on("click", function() {
  103. var parentsId = $(this).parent().attr("id");
  104. $("." + parentsId).toggle();
  105. if ($("." + parentsId).is(":visible")) {
  106. var audio = $("#" + parentsId + "Lyd")[0];
  107. audio.play();
  108. }
  109.  
  110. });
  111. } else {
  112.  
  113. $(".circle").off();
  114.  
  115. $("#info p").html("");
  116. $("#info").css("background-color","transparent");
  117.  
  118. $(".offer,.blomster,.rokelse,.vibhuti,.ganesha").css({
  119. "top": 0,
  120. "left": 0,
  121. "right": 0,
  122. "bottom": 0,
  123. "display": "inline"
  124. });
  125. $(".navn").css("position", "relative");
  126.  
  127. $("#draggable").css({
  128. "position": "relative",
  129. "top": 460 + "px",
  130. "left": 20 + "px"
  131. });
  132. }
  133.  
  134. });
  135.  
  136.  
  137.  
  138.  
  139. //DRAGGABLE EVENTS
  140. $("#draggable p").draggable({
  141. revert: true,
  142. snap: "#drop",
  143. snapMode: "inner",
  144. start: function(e, ui) {
  145. //ui.helper
  146. ui.helper.fadeTo(500, 1);
  147.  
  148. },
  149. stop: function(e, ui) {
  150. ui.helper.fadeTo(500, 1);
  151. }
  152. });
  153.  
  154. $("#bokser .circle").droppable({
  155.  
  156. drop: function(e, ui) {
  157.  
  158. var sirkelDiv = $(this).parent().attr("id");
  159. var svarDiv = ui.draggable.attr("data-navn");
  160.  
  161. if (sirkelDiv === svarDiv) {
  162. $("." + svarDiv).animate({
  163. "background-color": "green"
  164. }, 500);
  165.  
  166.  
  167. ui.draggable.draggable("disable");
  168. ui.draggable.draggable("option", "revert", "false");
  169. antRiktige++;
  170.  
  171.  
  172. } else {
  173. $(this).animate({
  174. "background-color": "red"
  175. }, 500);
  176. antFeil++;
  177. }
  178. checkWin();
  179. }
  180. });
  181.  
  182.  
  183. }
  184.  
  185. function checkWin() {
  186. if(antRiktige === 5) {
  187. if(antFeil <= 1) {
  188. alert("KJEMPEBRA, Du fikk " + antFeil + " feil.");
  189. } else if(antFeil > 3) {
  190. alert("Du må øve litt mer, Du fikk " + antFeil + " feil.");
  191. } else {
  192. alert("Bra!, Du fikk " + antFeil + " feil.");
  193. }
  194. $("#info").css("background-color","yellow");
  195. $("#info p").html("Prøv på nytt");
  196. }
  197. }
  198.  
  199. var init = function() {
  200. stilSettStart();
  201. settEvents();
  202. }();
  203. });
  204.  
  205.  
  206.  
  207. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement