<template> <div class="question-answer-session"> <Version2 /> </div></template><script setup lang="ts">// import Version1 from './version-2.vue'import Version2 from './version-2.vue'// import Version3 from './version-2.vue'</script><style scoped>.question-answer-session { min-height: 100vh; overflow: hidden;}</style>export interface QuestionItem { imgSrc: string question1?: string question2?: string}export const questionList: QuestionItem[] = [ { imgSrc: 'https://p5.music.126.net/obj/wonDlsKUwrLClGjCm8Kx/45063552550/76bf/6055/26e8/57a72c6c46587d8a77955e4b6cfadaae.png?imageView=1&type=webp&thumbnail=1004x0', }, { imgSrc: 'https://p5.music.126.net/obj/wonDlsKUwrLClGjCm8Kx/45064521651/2af1/a862/6995/0d276cfa1c041db1069c90b0c1456574.png?imageView=1&type=webp&thumbnail=1008x0', question1: 'https://p5.music.126.net/obj/wonDlsKUwrLClGjCm8Kx/45065513549/6d04/2ddc/37da/cd6ae967cf2e2ed437d0687e34f12f56.png?imageView=1&type=webp&thumbnail=480x0', question2: 'https://p5.music.126.net/obj/wonDlsKUwrLClGjCm8Kx/45047030773/8959/df2e/2722/c2c45b601db7773be2e2ec83703f7a95.png?imageView=1&type=webp&thumbnail=498x0', }, { imgSrc: 'https://p5.music.126.net/obj/wonDlsKUwrLClGjCm8Kx/45064479529/adeb/0084/5bbb/a4c18a0b3e6bc8700447409deaf97d61.png?imageView=1&type=webp&thumbnail=1008x0', question1: 'https://p5.music.126.net/obj/wonDlsKUwrLClGjCm8Kx/45064448605/95d1/7b6f/cff3/beb7469ef6b5f9b1b43c02cb0cc7baed.png?imageView=1&type=webp&thumbnail=470x0', question2: 'https://p5.music.126.net/obj/wonDlsKUwrLClGjCm8Kx/45064468685/2cd2/4dec/aa77/c9ea8efb40efac2a7fb253e8925ca902.png?imageView=1&type=webp&thumbnail=920x0', }, { imgSrc: 'https://p5.music.126.net/obj/wonDlsKUwrLClGjCm8Kx/45064580401/7279/3287/2423/705c543add0dc4e632d473dea78c2324.png?imageView=1&type=webp&thumbnail=1008x0', question1: 'https://p5.music.126.net/obj/wonDlsKUwrLClGjCm8Kx/45064527739/f826/eeba/baf3/14ce114acb980b93c9fdf1930ce3a7ac.png?imageView=1&type=webp&thumbnail=416x0', question2: 'https://p5.music.126.net/obj/wonDlsKUwrLClGjCm8Kx/45064551621/8082/19c6/f2ac/8d70f85e636fe69bf0cea1ef9e9d6b16.png?imageView=1&type=webp&thumbnail=1006x0', }, { imgSrc: 'https://p5.music.126.net/obj/wonDlsKUwrLClGjCm8Kx/45065369623/baf7/bcb0/71fe/f4debb741e7d0778943f16c9ebb1e9d3.png?imageView=1&type=webp&thumbnail=1004x0', },]<template> <div class="version version1"> <div v-for="(item, index) in questionList" :key="index" class="step-content" :class="[`step${index}`, currentStep !== index ? 'fade-item' : 'fade-enter-done']" > <img class="image-bg" :src="item.imgSrc" alt="" /> <div v-if="index === 0" class="begin-testing" @click="handleBeginTesting"></div> <img v-if="item.question1" class="question question1" :src="item.question1" alt="" @click="handleAnsweringQuestion" /> <img v-if="item.question2" class="question question2" :src="item.question2" alt="" @click="handleAnsweringQuestion" /> </div> </div></template><script setup lang="ts">import { ref } from 'vue'import { questionList } from './question-data'const currentStep = ref(0)const handleBeginTesting = () => { currentStep.value = 1}const handleAnsweringQuestion = () => { currentStep.value += 1}</script><style scoped>.version { position: relative; display: flex; width: 100%; min-height: 100vh; justify-content: center; overflow: hidden;}.step-content { position: absolute; top: 0; left: 50%; width: 100%; max-width: 500px; transform: translateX(-50%);}.begin-testing { position: absolute; top: 64.5%; left: 50%; width: 63%; height: 95px; cursor: pointer; transform: translateX(-50%);}.image-bg { width: 100%; height: auto; transition: opacity 1s ease-in-out;}.question { position: absolute; z-index: 100; height: auto; cursor: pointer;}.step1 .question1 { top: 28%; right: 6%; width: 36%;}.step1 .question2 { top: 57%; right: 59%; width: 35%;}.step2 .question1 { top: 25%; right: 6%; width: 46%;}.step2 .question2 { top: 57%; right: 59%; width: 35%;}.step3 .question1 { top: 27%; right: 3%; width: 46%;}.step3 .question2 { top: 39%; right: 58%; width: 40%;}.fade-item { z-index: 10; opacity: 0; transition: opacity 1s ease-in-out;}.fade-enter-done { z-index: 100; opacity: 1; transition: opacity 1s ease-in-out;}</style><template> <div class="version version2"> <div v-for="(item, index) in questionList" :key="index" class="step-content" :class="[`step${index}`, currentStep === index ? 'fade-enter-done' : 'fade-item']" > <img class="image-bg" :src="item.imgSrc" alt="" :style="{ opacity: animationStates[index]?.imageOpacity ?? 0 }" @load="handleImageLoad(index)" /> <div v-if="index === 0" class="begin-testing" @click="handleBeginTesting"></div> <img v-if="item.question1" class="question question1" :src="item.question1" alt="" :style="{ opacity: animationStates[index]?.question1Opacity ?? 0 }" @click="handleAnsweringQuestion" /> <img v-if="item.question2" class="question question2" :src="item.question2" alt="" :style="{ opacity: animationStates[index]?.question2Opacity ?? 0 }" @click="handleAnsweringQuestion" /> </div> </div></template><script setup lang="ts">import { onBeforeUnmount, reactive, ref, watch } from 'vue'import { questionList } from './question-data'const currentStep = ref(0)const animationStates = reactive( questionList.map(() => ({ imageOpacity: 0, question1Opacity: 0, question2Opacity: 0, imageLoaded: false, })),)let timers: number[] = []const clearTimers = () => { timers.forEach((timer) => window.clearTimeout(timer)) timers = []}const resetAnimation = (index: number) => { const state = animationStates[index] if (!state) { return } state.imageOpacity = 0 state.question1Opacity = 0 state.question2Opacity = 0}const runAnimation = (index: number) => { const item = questionList[index] const state = animationStates[index] if (!item || !state?.imageLoaded || currentStep.value !== index) { return } clearTimers() state.imageOpacity = 1 if (item.question1) { const question1Timer = window.setTimeout(() => { state.question1Opacity = 1 if (item.question2) { const question2Timer = window.setTimeout(() => { state.question2Opacity = 1 }, 500) timers.push(question2Timer) } }, 500) timers.push(question1Timer) }}const handleImageLoad = (index: number) => { const state = animationStates[index] if (!state) { return } state.imageLoaded = true runAnimation(index)}const handleBeginTesting = () => { currentStep.value = 1}const handleAnsweringQuestion = () => { currentStep.value += 1}watch(currentStep, (index) => { clearTimers() resetAnimation(index) runAnimation(index)})onBeforeUnmount(clearTimers)</script><style scoped>.version { position: relative; display: flex; width: 100%; min-height: 100vh; justify-content: center; overflow: hidden;}.step-content { position: absolute; top: 0; left: 50%; width: 100%; max-width: 500px; transform: translateX(-50%);}.begin-testing { position: absolute; top: 64.5%; left: 50%; width: 63%; height: 95px; cursor: pointer; transform: translateX(-50%);}.image-bg { width: 100%; height: auto; transition: opacity 1s ease-in-out;}.question { position: absolute; z-index: 100; height: auto; cursor: pointer; transition: opacity 1s ease-in-out;}.step1 .question1 { top: 28%; right: 6%; width: 36%;}.step1 .question2 { top: 57%; right: 59%; width: 35%;}.step2 .question1 { top: 25%; right: 6%; width: 46%;}.step2 .question2 { top: 57%; right: 59%; width: 35%;}.step3 .question1 { top: 27%; right: 3%; width: 46%;}.step3 .question2 { top: 39%; right: 58%; width: 40%;}.fade-item { z-index: 10;}.fade-enter-done { z-index: 100;}</style><template> <div class="version version3"> <div v-for="{ item, index } in renderedItems" :key="index" class="step-content" :class="[`step${index}`, currentStep === index ? 'fade-enter-done' : 'fade-item']" > <img class="image-bg" :src="item.imgSrc" alt="" :style="{ opacity: animationStates[index]?.imageOpacity ?? 0 }" @load="handleImageLoad(index)" /> <div v-if="index === 0" class="begin-testing" @click="handleBeginTesting"></div> <img v-if="item.question1" class="question question1" :src="item.question1" alt="" :style="{ opacity: animationStates[index]?.question1Opacity ?? 0 }" @click="handleAnsweringQuestion" /> <img v-if="item.question2" class="question question2" :src="item.question2" alt="" :style="{ opacity: animationStates[index]?.question2Opacity ?? 0 }" @click="handleAnsweringQuestion" /> </div> </div></template><script setup lang="ts">import { computed, onBeforeUnmount, reactive, ref, watch } from 'vue'import { questionList } from './question-data'const currentStep = ref(0)const animationStates = reactive( questionList.map(() => ({ imageOpacity: 0, question1Opacity: 0, question2Opacity: 0, imageLoaded: false, })),)const renderedItems = computed(() => questionList .map((item, index) => ({ item, index })) .filter(({ index }) => index <= currentStep.value + 1),)let timers: number[] = []const clearTimers = () => { timers.forEach((timer) => window.clearTimeout(timer)) timers = []}const resetAnimation = (index: number) => { const state = animationStates[index] if (!state) { return } state.imageOpacity = 0 state.question1Opacity = 0 state.question2Opacity = 0}const runAnimation = (index: number) => { const item = questionList[index] const state = animationStates[index] if (!item || !state?.imageLoaded || currentStep.value !== index) { return } clearTimers() state.imageOpacity = 1 if (item.question1) { const question1Timer = window.setTimeout(() => { state.question1Opacity = 1 if (item.question2) { const question2Timer = window.setTimeout(() => { state.question2Opacity = 1 }, 500) timers.push(question2Timer) } }, 500) timers.push(question1Timer) }}const handleImageLoad = (index: number) => { const state = animationStates[index] if (!state) { return } state.imageLoaded = true runAnimation(index)}const handleBeginTesting = () => { currentStep.value = 1}const handleAnsweringQuestion = () => { currentStep.value += 1}watch(currentStep, (index) => { clearTimers() resetAnimation(index) runAnimation(index)})onBeforeUnmount(clearTimers)</script><style scoped>.version { position: relative; display: flex; width: 100%; min-height: 100vh; justify-content: center; overflow: hidden;}.step-content { position: absolute; top: 0; left: 50%; width: 100%; max-width: 500px; transform: translateX(-50%);}.begin-testing { position: absolute; top: 64.5%; left: 50%; width: 63%; height: 95px; cursor: pointer; transform: translateX(-50%);}.image-bg { width: 100%; height: auto; transition: opacity 1s ease-in-out;}.question { position: absolute; z-index: 100; height: auto; cursor: pointer; transition: opacity 1s ease-in-out;}.step1 .question1 { top: 28%; right: 6%; width: 36%;}.step1 .question2 { top: 57%; right: 59%; width: 35%;}.step2 .question1 { top: 25%; right: 6%; width: 46%;}.step2 .question2 { top: 57%; right: 59%; width: 35%;}.step3 .question1 { top: 27%; right: 3%; width: 46%;}.step3 .question2 { top: 39%; right: 58%; width: 40%;}.fade-item { z-index: 10;}.fade-enter-done { z-index: 100;}</style>