【发布时间】:2021-05-11 15:27:27
【问题描述】:
我正在尝试构建某种淡入淡出滑块,但在转换之间出现了奇怪的跳跃,已经尝试过来自 this question 的解决方案,但它不适用于我的情况。我不知道为什么会发生这种情况,为了清楚起见,请看一下这个 gif
如果可能的话,我想知道是哪一部分导致了这个问题,以及我该如何解决它。任何形式的帮助将不胜感激。请看一下我的脚本.. 提前致谢!
<template>
<header class="hero">
<div class="container">
<div class="textbox">
<transition name="fade" v-for="(slide, i) in slides" :key="slide">
<h1 class="punchline" v-if="current == i">{{ slide }}</h1>
</transition>
<NuxtLink class="link" to="/">
<div class="icon-wrapper">
<Icon icon="chevron-right" />
</div>
</NuxtLink>
</div>
<div class="indicator">
<span
v-for="(slide, i) in slides"
:key="slide"
:class="{ active: current == i }"
class="item"
@click="animateTo(i)"
/>
</div>
</div>
<Vector :class="color" class="stick-overlay stick-top" file="model-stick" />
<Vector
:class="color"
class="stick-overlay stick-bottom"
file="model-stick"
/>
</header>
</template>
<script>
export default {
data() {
return {
current: 0,
slides: ['Slide 001', 'Slide 002', 'Slide 003']
}
},
computed: {
color() {
if (this.current == 1) return 'blue'
if (this.current == 2) return 'purple'
return 'default'
}
},
methods: {
animateTo(index) {
this.current = index
}
}
}
</script>
<style lang="scss" scoped>
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.5s;
}
.fade-enter,
.fade-leave-to {
opacity: 0;
}
.hero {
@apply flex;
@apply justify-center;
@apply items-center;
@apply text-white;
@apply relative;
height: 810px;
background: url('/images/img-hero.png');
background-position: center;
background-size: cover;
background-repeat: no-repeat;
.textbox {
@apply relative;
@apply text-center;
@apply mb-20;
.punchline {
@apply text-3xl;
@apply font-semibold;
@apply leading-relaxed;
@apply mb-10;
}
.link {
@apply flex;
@apply justify-center;
.icon-wrapper {
@apply h-16 w-16;
@apply border;
@apply border-white;
@apply flex;
@apply justify-center;
@apply items-center;
@apply rounded-full;
}
}
}
.indicator {
@apply flex;
@apply justify-between;
@apply items-center;
@apply px-20;
.item {
@apply inline-block;
@apply h-2 w-2;
@apply border;
@apply border-white;
@apply rounded-full;
@apply transition-colors;
@apply duration-300;
&.active {
@apply bg-white;
}
}
}
.stick-overlay {
@apply absolute;
@apply z-0;
&.stick-top {
top: -75%;
left: -75%;
transform: scale(0.6) rotate(180deg);
}
&.stick-bottom {
@apply block;
bottom: -80%;
left: -5%;
transform: scale(0.6);
}
&::v-deep svg path {
@apply transition-all;
@apply duration-1000;
}
&.default ::v-deep svg path {
fill: rgba(0, 40, 255, 0.5);
}
&.blue ::v-deep svg path {
fill: rgba(33, 167, 252, 0.3);
}
&.purple ::v-deep svg path {
fill: rgba(119, 41, 251, 0.3);
}
}
}
</style>
【问题讨论】:
标签: vue.js nuxt.js tailwind-css