ef-bone.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <view style="position: relative;">
  3. <view v-if="!bHit&&bMove" class="ef-abs">
  4. <view class="ef-parent">
  5. <view class="ef-container">
  6. <view class="focusEnergy playEnergy" :style="{
  7. '--time':duration,
  8. backgroundImage:`url(${energyImageSrc})`}">
  9. </view>
  10. </view>
  11. </view>
  12. </view>
  13. <view :class="bHit?' ef-hidden ':''" class="flex justify-around " style="margin-bottom: 16rpx; height: 300rpx;">
  14. <view style="position: relative;width: 133rpx;">
  15. <view :class="[bLeftHidden?'ef-hidden ':'',efLeftValue==0?'':'ef-ani']" class="flex flex-direction justify-between ef-leftHand"
  16. :style="{'left': efLeftValue+'px'}">
  17. <image src="/static/modal/boxing-post/left-hook-h@2x.png" :class="bLeftHidden?'':' ef-image-change '" class="ef-png " mode="aspectFit"></image>
  18. <view class="text-white text-13px" style="margin: 35rpx 0;">左勾拳</view>
  19. </view>
  20. </view>
  21. <view>
  22. <view :class="bMidHidden?'ef-mid-ani ':''" class="flex flex-direction justify-between ef-midHand">
  23. <image src="/static/modal/boxing-post/straight-h@2x.png" :class="bMidHidden?'':' ef-image-change '" class="ef-png " mode="aspectFit"></image>
  24. <view class="text-white text-13px" style="margin: 35rpx 0;">直拳</view>
  25. </view>
  26. </view>
  27. <view style="position: relative;width: 133rpx;">
  28. <view :class="[bRightHidden?'ef-hidden ':'',efRightValue==0?'':'ef-ani']" class="flex flex-direction justify-between ef-rightHand"
  29. :style="{'left': efRightValue+'px'}">
  30. <image src="/static/modal/boxing-post/right-hook-h@2x.png" :class="bRightHidden?'':' ef-image-change '" class="ef-png " mode="aspectFit"></image>
  31. <view class="text-white text-13px" style="margin: 35rpx 0;">右勾拳</view>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- <button @tap="onMoveLeftAndRightPos">123</button> -->
  36. <!-- <button @tap="onReset">reset</button> -->
  37. <!-- <button @tap="onEFHit">hit</button> -->
  38. <view v-if="bHit" class="ef-abs" style="left: 50rpx;top: 100rpx;">
  39. <view class="ef-parent">
  40. <view class="ef-container">
  41. <view class="ef-bone playBone" :style="{
  42. '--time':duration,
  43. backgroundImage:`url(${boneImageSrc})`}">
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import boneImageSrc from "@/static/modal/boxing-post/ef/bone.png"
  52. import energyImageSrc from "@/static/modal/boxing-post/ef/focusEnergy.png"
  53. export default {
  54. props: {
  55. duration: {
  56. type: Number,
  57. default: 0.8
  58. }
  59. },
  60. data() {
  61. return {
  62. boneImageSrc: boneImageSrc,
  63. energyImageSrc: energyImageSrc,
  64. efLeftHand: null,
  65. efRightHand: null,
  66. efMidHand: null,
  67. efLeftValue: 0,
  68. efRightValue: 0,
  69. randomIndex: 0,
  70. bLeftHidden: false,
  71. bMidHidden: false,
  72. bRightHidden: false,
  73. bMove: false,
  74. bHit: false,
  75. gasUrl: "/static/modal/boxing-post/ef/gas.mp3",
  76. gasUpUrl: "/static/modal/boxing-post/ef/gasUp.mp3",
  77. hitBoneUrl: "/static/modal/boxing-post/ef/hitBone.mp3",
  78. giveGoTipUrl: "/static/modal/boxing-post/tipGiveItAGo.mp3",
  79. efAudioContext: null,
  80. efAudioLoop: null,
  81. efTimeout: null,
  82. };
  83. },
  84. created() {
  85. },
  86. beforeDestroy() {
  87. // this.efAudioContext.stop();
  88. if (this.efAudioContext)
  89. this.efAudioContext.destroy();
  90. if (this.efTimeout)
  91. clearTimeout(this.efTimeout);
  92. // if(this.efAudioLoop)
  93. // clearInterval(this.efAudioLoop);
  94. },
  95. mounted() {
  96. setTimeout(() => {
  97. this.getMidHandSize()
  98. }, 100)
  99. let _self = this;
  100. _self.efAudioContext = uni.createInnerAudioContext();
  101. _self.efAudioContext.autoplay = true;
  102. _self.efAudioContext.src = _self.gasUpUrl;
  103. _self.efAudioContext.volume = 0.5;
  104. _self.efTimeout = setTimeout(() => {
  105. _self.efAudioContext.stop();
  106. _self.efAudioContext.src = _self.gasUrl;
  107. _self.efAudioContext.loop = true;
  108. _self.efAudioContext.volume = 0.2;
  109. _self.efAudioContext.play();
  110. }, 1500);
  111. },
  112. methods: {
  113. getMidHandSize() {
  114. let _self = this;
  115. const views1 = uni.createSelectorQuery().in(this).select('.ef-midHand')
  116. views1.boundingClientRect(data => {
  117. console.log("ef-midHand:", data);
  118. _self.efMidHand = data;
  119. }).exec();
  120. const views2 = uni.createSelectorQuery().in(this).select('.ef-leftHand');
  121. views2.boundingClientRect(data => {
  122. console.log("ef-leftHand:", data);
  123. _self.efLeftHand = data;
  124. }).exec();
  125. const views3 = uni.createSelectorQuery().in(this).select('.ef-rightHand');
  126. views3.boundingClientRect(data => {
  127. console.log("ef-rightHand:", data);
  128. _self.efRightHand = data;
  129. }).exec();
  130. setTimeout(() => {
  131. this.onMoveLeftAndRightPos();
  132. }, 200);
  133. },
  134. onReset() {
  135. let _self = this;
  136. _self.efLeftValue = 0;
  137. _self.efRightValue = 0;
  138. _self.bLeftHidden = false;
  139. _self.bRightHidden = false;
  140. _self.bMidHidden = false;
  141. _self.bMove = false;
  142. _self.bHit = false;
  143. },
  144. //移动位置
  145. onMoveLeftAndRightPos() {
  146. let _self = this;
  147. _self.efLeftValue = _self.efMidHand.left - _self.efLeftHand.left;
  148. _self.efRightValue = _self.efMidHand.left - _self.efRightHand.left;
  149. _self.bMove = true;
  150. //随机一个
  151. _self.randomIndex = Math.floor(Math.random() * 3);
  152. let _randomName = "";
  153. let _direction = "";
  154. if (0 === _self.randomIndex) {
  155. //显示左
  156. _self.bRightHidden = true;
  157. _self.bMidHidden = true;
  158. _randomName = "左勾拳";
  159. _direction = "xRCount";
  160. } else if (1 === _self.randomIndex) {
  161. //显示右
  162. _self.bLeftHidden = true;
  163. _self.bMidHidden = true;
  164. _randomName = "右勾拳";
  165. _direction = "xLCount";
  166. } else if (2 === _self.randomIndex) {
  167. //显示中
  168. _self.bLeftHidden = true;
  169. _self.bRightHidden = true;
  170. _randomName = "直拳";
  171. _direction = "zLCount";
  172. }
  173. this.$emit("randomIndex", {
  174. index: _self.randomIndex,
  175. name: _randomName,
  176. direction: _direction
  177. });
  178. },
  179. onEFHit(callback) {
  180. this.bHit = true;
  181. this.efAudioContext.stop();
  182. this.efAudioContext.src = this.hitBoneUrl;
  183. this.efAudioContext.loop = false;
  184. this.efAudioContext.volume = 0.7;
  185. this.efAudioContext.play();
  186. setTimeout(() => {
  187. this.onReset();
  188. if (callback)
  189. callback();
  190. }, this.duration * 1000);
  191. }
  192. }
  193. }
  194. </script>
  195. <style lang="scss">
  196. .ef-abs {
  197. position: absolute;
  198. top: 0;
  199. right: 0;
  200. left: 0;
  201. display: flex;
  202. justify-content: center;
  203. pointer-events: none;
  204. transform: scale(2.5);
  205. }
  206. .ef-parent {
  207. // border: 1rpx solid #ffaa7f;
  208. position: relative;
  209. display: flex;
  210. justify-content: center;
  211. overflow: hidden;
  212. pointer-events: none;
  213. }
  214. .ef-container {
  215. width: 100%;
  216. height: 187px;
  217. position: relative;
  218. }
  219. .ef-bone {
  220. // background-color: #007AFF;
  221. background-size: cover;
  222. height: 112px;
  223. width: 102px;
  224. position: relative;
  225. top: 0;
  226. left: 0;
  227. }
  228. .playBone {
  229. animation: runBone calc(var(--time) * 1s) steps(1, start) forwards;
  230. -webkit-animation: runBone calc(var(--time) * 1s) steps(1, start) forwards;
  231. }
  232. .focusEnergy {
  233. // background-color: #007AFF;
  234. background-size: cover;
  235. height: 152px;
  236. width: 105px;
  237. position: relative;
  238. top: 0;
  239. left: 0;
  240. }
  241. .playEnergy {
  242. animation: runEnergy calc(var(--time) * 1s) steps(1, start) infinite;
  243. -webkit-animation: runEnergy calc(var(--time) * 1s) steps(1, start) infinite;
  244. animation-play-state: running;
  245. }
  246. @keyframes runBone {
  247. @for $i from 0 through 13 {
  248. #{$i*8.3}% {
  249. background-position: -0px -112px*$i;
  250. }
  251. }
  252. }
  253. @-webkit-keyframes runBone {
  254. @for $i from 0 through 13 {
  255. #{$i*8.3}% {
  256. background-position: -0px -112px*$i;
  257. }
  258. }
  259. }
  260. @keyframes runEnergy {
  261. @for $i from 0 through 14 {
  262. #{$i*7.14}% {
  263. background-position: -0px -152px*$i;
  264. }
  265. }
  266. }
  267. @-webkit-keyframes runEnergy {
  268. @for $i from 0 through 14 {
  269. #{$i*7.14}% {
  270. background-position: -0px -152px*$i;
  271. }
  272. }
  273. }
  274. .ef-png {
  275. margin-top: 40rpx;
  276. width: 133rpx;
  277. height: 133rpx;
  278. transition: transform 1s;
  279. }
  280. .ef-change {
  281. transform: scale(1.58);
  282. }
  283. .ef-image-change {
  284. animation-name: myEfImagechange;
  285. /*动画的名字*/
  286. animation-duration: 300ms;
  287. /*定义动画完成一个周期所需要的时间,以秒或毫秒计*/
  288. animation-iteration-count: infinite;
  289. /*定义动画的播放次数,这里是无限播放*/
  290. animation-direction: alternate;
  291. /*定义是否应该轮流反向播放动画,这里是动画轮流播放*/
  292. }
  293. @keyframes myEfImagechange {
  294. 0% {
  295. transform: scale(1);
  296. }
  297. 100% {
  298. transform: scale(1.4);
  299. }
  300. }
  301. .ef-leftHand {
  302. position: absolute;
  303. left: 0px;
  304. }
  305. .ef-ani {
  306. transition: opacity 1s, left 1s;
  307. }
  308. .ef-rightHand {
  309. position: absolute;
  310. left: 0px;
  311. }
  312. .ef-mid-ani {
  313. transition: opacity 1s;
  314. opacity: 0;
  315. }
  316. .ef-opacity-ani {
  317. transition: opacity 1s;
  318. }
  319. .ef-hidden {
  320. // visibility: hidden;
  321. opacity: 0;
  322. }
  323. </style>