SingleLongImageSerialFrames.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <div
  3. class="single-long-image-serial-frames"
  4. >
  5. <img
  6. class="long-image"
  7. :style="{
  8. transitionDuration: transitionDuration + 'ms',
  9. transitionTimingFunction: `steps(${frameNumber - 1}, jump-end)`,
  10. left: status === 'initial' ? 0 : `calc(-100% * ${frameNumber - 1})`
  11. }"
  12. :src="imageSrc"
  13. alt=""
  14. @dragstart.prevent
  15. >
  16. <HotSpot
  17. class="hot-spot"
  18. :style="{
  19. left: hotSpotCenterPosLeft,
  20. top: hotSpotCenterPosTop,
  21. }"
  22. @click="onClickHotSpot"
  23. />
  24. </div>
  25. </template>
  26. <script>
  27. export default {
  28. props: {
  29. imageSrc: {
  30. type: String,
  31. required: true,
  32. },
  33. frameNumber: {
  34. type: Number,
  35. required: true,
  36. },
  37. transitionDuration: {
  38. type: Number,
  39. default: 2500,
  40. },
  41. hotSpotCenterPosLeft: {
  42. type: String,
  43. default: '50%'
  44. },
  45. hotSpotCenterPosTop: {
  46. type: String,
  47. default: '50%',
  48. },
  49. },
  50. data() {
  51. return {
  52. status: 'initial', // 'initial', 'variant'
  53. isChanging: false,
  54. }
  55. },
  56. methods: {
  57. onClickHotSpot() {
  58. if (this.isChanging) {
  59. return
  60. } else {
  61. if (this.status === 'initial') {
  62. this.status = 'variant'
  63. } else {
  64. this.status = 'initial'
  65. }
  66. this.isChanging = true
  67. setTimeout(() => {
  68. this.isChanging = false
  69. }, 2500)
  70. }
  71. },
  72. }
  73. }
  74. </script>
  75. <style lang="less" scoped>
  76. .single-long-image-serial-frames {
  77. position: absolute;
  78. overflow: hidden;
  79. > .long-image {
  80. position: absolute;
  81. height: 100%;
  82. transition-property: left;
  83. }
  84. > .hot-spot {
  85. position: absolute;
  86. transform: translate(-50%, -50%);
  87. }
  88. }
  89. </style>