index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div class="container">
  3. <div class="content">
  4. <img
  5. class="animate__animated"
  6. :class="{animate__fadeInDown: inited ? item[2] : true}"
  7. v-for="(item, index) in items"
  8. :key="index"
  9. :style="{
  10. width: item[3] + 'px',
  11. top: item[0] + 'px',
  12. left: item[1] + 'px',
  13. 'animation-delay': (!inited ? (index * 0.3) + 's' : '0s'),
  14. 'z-index': 6 - index
  15. }"
  16. :src="require(`./images/${index + 1}.png`)"
  17. />
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. const items = [
  23. [60, 50, false, 421],
  24. [120, 220, false, 466],
  25. [180, -100, false, 581],
  26. [240 , -15, false, 520],
  27. [305, 188, false, 519],
  28. ]
  29. export default {
  30. name: 'safe',
  31. data() {
  32. return {
  33. items,
  34. inited: false,
  35. }
  36. },
  37. mounted() {
  38. let timer = null
  39. timer = setTimeout(() => {
  40. this.inited = true
  41. clearTimeout(timer)
  42. }, 2500)
  43. },
  44. methods: {
  45. mouseenter(index) {
  46. let timer = null
  47. const _items = [...this.items]
  48. _items[index][2] = true
  49. this.items = _items
  50. setTimeout(() => {
  51. this.mouseleave(index)
  52. clearTimeout(timer)
  53. }, 600)
  54. },
  55. mouseleave(index) {
  56. const _items = [...this.items]
  57. _items[index][2] = false
  58. this.items = _items
  59. }
  60. }
  61. }
  62. </script>
  63. <style lang="less" scoped>
  64. .container{
  65. min-height: 500px;
  66. .content{
  67. width: 581px;
  68. margin: 50px auto;
  69. margin-left: 280px;
  70. position: relative;
  71. >img{
  72. display: block;
  73. position: absolute;
  74. transition: all .3s ease-in-out;
  75. &:hover{
  76. margin-top: -10px;
  77. }
  78. }
  79. }
  80. }
  81. </style>