rain_line.vue 1.8 KB

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