Guest User

Untitled

a guest
Nov 21st, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. <div id="vue-app-one">
  2. <!-- the bag images -->
  3. <div id="bag" v-bind:class="[animationToggle ? activeClass : 'swingLeft',
  4. 'noSwing']" v-bind:class="{ burst: ended }"></div>
  5.  
  6. <!-- health meter -->
  7. <div id="bag-health">
  8. <div v-bind:class="[danger ? activeClass : 'dangerous', 'safe']" v-
  9. bind:style="{ width: health + '%'}"></div>
  10. </div>
  11.  
  12.  
  13. <!-- the game buttons -->
  14.  
  15. <div id="controls">
  16. <button v-on:click="punch" v-show="!ended">Punch it!</button>
  17. <button v-on:click="restart">Restart game</button>
  18. </div>
  19.  
  20. </div>
  21.  
  22. <div id="bag" v-bind:class="[animationToggle ? activeClass : 'swingLeft',
  23. 'noSwing']" v-bind:class="{ burst: ended }"></div>
  24.  
  25. var one = new Vue({
  26. el: '#vue-app-one',
  27. data: {
  28. health: 100, //init health bar, this works
  29. ended: false, // init ended state, works partially
  30. punched: false, //init punched, don't need for now
  31. danger: false, // this works
  32. animationToggle: false, // there is a problem with this
  33. activeClass: "" // have to init or I get the errors in the console
  34. },
  35. methods: {
  36.  
  37. punch: function(){
  38. this.health -=10; //works
  39. this.animationToggle= true; // is set on click
  40. if(this.health <= 0){
  41. this.ended = true; // works partially, the background img change is not working ,though
  42. }
  43. if(this.health <= 20){
  44. this.danger = true; // works
  45. }
  46. else{
  47. this.danger = false;
  48. }
  49. setTimeout(function () {
  50. this.animationToggle = false // I am not sure this ever works, give no error, but I am still not sure
  51. }.bind(this),500);
  52.  
  53. },
  54. restart: function(){
  55. this.health =100;
  56. this.ended = false; // works partially, no img change when health is 0, though
  57. }
  58. }
  59.  
  60. });
  61.  
  62. #bag.noSwing {
  63. width: 300px;
  64. height: 500px;
  65. margin: -80px auto;
  66. background: url("https://3.imimg.com/data3/VM/TI/MY-18093/classical-heavy-
  67. bag-250x250.png") center no-repeat;
  68. background-size: 70%;
  69. -webkit-animation-name: swingRight;
  70. -webkit-animation-duration:1s;
  71. -webkit-animation-iteration-count: 1;
  72. -webkit-transition-timing-function: cubic-bezier(.11,.91,.91,.39);
  73. -webkit-animation-fill-mode: forwards;
  74. -webkit-transform-origin: center;
  75. transform-origin: center;
  76. }
  77.  
  78. #bag.swingLeft {
  79. width: 300px;
  80. height: 500px;
  81. margin: -80px auto;
  82. background: url("https://3.imimg.com/data3/VM/TI/MY-18093/classical-heavy-
  83. bag-250x250.png") center no-repeat;
  84. background-size: 70%;
  85. -webkit-animation-name: swingLeft;
  86. -webkit-animation-duration:1s;
  87. -webkit-animation-iteration-count: 1;
  88. -webkit-transform-origin: right;
  89. transform-origin: right;
  90. -webkit-transition-timing-function: cubic-bezier(.91,.11,.31,.69);
  91.  
  92. }
  93.  
  94.  
  95. @keyframes swingLeft {
  96. 0% { -webkit-transform: rotate (0deg); transform: rotate (0deg); }
  97. 20% { -webkit-transform: rotate (-20deg); transform: rotate (-20deg); }
  98. 50% { -webkit-transform: rotate (20deg); transform: rotate (20deg); }
  99. 70% { -webkit-transform: rotate (-10deg); transform: rotate (-10deg); }
  100. 100% { -webkit-transform: rotate (0deg); transform: rotate (0deg); }
  101. }
  102.  
  103. @keyframes swingRight {
  104. 0% { -webkit-transform: rotate (0deg); transform: rotate (0deg); }
  105. 20% { -webkit-transform: rotate (20deg); transform: rotate (20deg); }
  106. 50% { -webkit-transform: rotate (-20deg); transform: rotate (-20deg); }
  107. 70% { -webkit-transform: rotate (10deg); transform: rotate (10deg); }
  108. 100% { -webkit-transform: rotate (0deg); transform: rotate (0deg); }
  109. }
  110.  
  111. #bag.burst {
  112.  
  113. background: url("http://i.imgur.com/oRUzTNx.jpg") center no-repeat;
  114. background-size: 70%;
  115.  
  116. }
  117.  
  118. #bag-health {
  119. width: 200px;
  120. border: 2px solid #004;
  121. margin: -80px auto 20px auto;
  122. }
  123.  
  124. #bag-health div.safe {
  125. height: 20px;
  126. background: #44c466;
  127. }
Add Comment
Please, Sign In to add comment