rain_item.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <image :src="resource.red_envelope" class="red-package" :style="{left: left + 'px'}"
  3. :animation='animationData' @click="lottery"></image>
  4. </template>
  5. <script>
  6. import resource from '@/utils/resource'
  7. export default {
  8. props: {
  9. delay: Number
  10. },
  11. data() {
  12. return {
  13. resource,
  14. left: 38,
  15. animationData: null
  16. }
  17. },
  18. created() {
  19. const timingFunctions = ['linear', 'ease', 'ease-out', 'ease-in-out']
  20. let index = Math.floor(Math.random() * 4)
  21. this.left = Math.floor(Math.random() * 262 + 38)
  22. this.animation = wx.createAnimation({
  23. timingFunction: timingFunctions[index],
  24. delay: this.delay
  25. })
  26. },
  27. mounted() {
  28. this.height = this.$store.state.systemInfo.screenHeight + 189
  29. this.startAnimal()
  30. },
  31. beforeDestroy() {
  32. this.animation = null
  33. this.animationData = null
  34. },
  35. methods: {
  36. startAnimal() {
  37. // this.animation.translateY('-189px').step({
  38. // duration: 0
  39. // })
  40. // this.animationData = this.animation.export()
  41. this.duration = Math.floor(Math.random() * 4 + 5) * 1000
  42. setTimeout(() => {
  43. this.animation.translateY(this.height + 'px').step({
  44. duration: this.duration
  45. })
  46. this.animationData = this.animation.export()
  47. }, 50)
  48. },
  49. lottery() {
  50. this.$emit('lottery')
  51. }
  52. }
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. .red-package {
  57. position: fixed;
  58. top: -189rpx;
  59. width: 32px;
  60. height: 89px;
  61. }
  62. </style>