vue transition 的 从下往上进入 从上往下进入 从右往左进入 从左往右进入效果


1.从下往上进入
<transition name="pull-up">
 .....


 .....


</transition>


2.从上往下进入


<transition name="drop-down">


 .....


 .....


</transition>








%common1 {
  opacity: 1;
  -ms-transform: scaleY(1);
  transform: scaleY(1);
  transition: transform 0.5s cubic-bezier(0.23, 1, 0.32, 1) 0.1s,
  opacity 0.3s cubic-bezier(0.23, 1, 0.32, 1) 0.1s;
  -ms-transform-origin: center top;
  transform-origin: center top;
}




.pull-up-enter-active,
.pull-up-leave-active {
  @extend %common1;
  transform-origin: center bottom;
}




.pull-up-enter,
.pull-up-leave-active,
.drop-down-enter,
.drop-down-leave-active {
  opacity: 0;
  -ms-transform: scaleY(0);
  transform: scaleY(0);
}




.drop-down-enter-active,
.drop-down-leave-active {
  @extend %common1;
  transform-origin: center top;
}




2.从右往左进入
<transition name="right-slide">
 .....


 .....


</transition>








.right-slide-enter,
.right-slide-leave-active {
transform: translateX(130px);
}


.right-slide-leave-active,
.right-slide-enter-active {
transition: all0.3s;
}
2.从左往右进入
<transition name="slide-right">
 .....


 .....


</transition>






.slide-right-enter,
.slide-right-leave-active {
transform: translateX(-350px);
}


.slide-right-leave-active,
.slide-right-enter-active {
transition: all0.3s 0.3s cubic-bezier(0.33, 0.25, 0.33, 1);
}


您好!针对您的问题,需要在vue3、ts项目中实现一个横向列表,并且在滑动到最后一条数据时,跳转至详情页。下面是一种可能的实现方式: 1. 使用Vue3的Composition API创建一个组件,命名为`HorizontalList`,该组件包含以下几个属性: - `data`:用于存储列表数据的数组; - `pageSize`:每页显示的数据条数; - `currentIndex`:当前页码; - `totalPage`:总页数; - `showPrevBtn`:是否显示上一页按钮; - `showNextBtn`:是否显示下一页按钮; - `showDetail`:是否显示详情页; - `currentDetailIndex`:当前详情页的索引。 2. 在`HorizontalList`组件中,使用`watchEffect`监听`data`的变化,计算总页数`totalPage`,以及是否需要显示上一页和下一页按钮。 3. 在`HorizontalList`组件的模板中,使用`v-for`指令遍历当前页的数据,并使用`v-if`指令判断是否需要显示详情页。 4. 在`HorizontalList`组件中,使用`@click`事件监听上一页和下一页按钮的点击事件,并更新`currentIndex`的值。 5. 在`HorizontalList`组件中,使用`@touchstart`和`@touchmove`事件监听手指触摸和滑动事件,并根据滑动的距离更新列表的位置。 6. 在`HorizontalList`组件中,使用`@click`事件监听列表项的点击事件,如果当前显示的是最后一页,并且点击的是最后一条数据,则跳转至详情页。 7. 在`HorizontalList`组件中,使用`router-link`组件实现详情页的路由跳转,并传递当前详情页的索引作为参数。 以上是一种可能的实现方式,具体代码实现可以参考以下示例代码: ```html <template> <div class="horizontal-list"> <div class="list-wrapper" :style="{ transform: 'translateX(' + position + ')' }"> <div class="list-item" v-for="(item, index) in currentData" :key="index" @click="handleItemClick(index)"> {{ item }} </div> <router-link v-if="showDetail" class="detail" :to="{ name: 'detail', params: { index: currentDetailIndex } }"> {{ data[currentDetailIndex] }} </router-link> </div> <div class="pagination"> <button class="prev" :disabled="!showPrevBtn" @click="handlePrevClick">上一页</button> <button class="next" :disabled="!showNextBtn" @click="handleNextClick">下一页</button> </div> </div> </template> <script lang="ts"> import { defineComponent, watchEffect, ref } from 'vue'; import { useRoute, useRouter } from 'vue-router'; export default defineComponent({ name: 'HorizontalList', props: { data: { type: Array, required: true, }, pageSize: { type: Number, default: 3, }, }, setup(props) { const router = useRouter(); const route = useRoute(); const currentIndex = ref(0); const currentDetailIndex = ref(-1); const showPrevBtn = ref(false); const showNextBtn = ref(true); const showDetail = ref(false); const totalPage = ref(0); const position = ref('0'); const currentData = ref<Array<string>>([]); const calculateTotalPage = () => { totalPage.value = Math.ceil(props.data.length / props.pageSize); }; const calculateCurrentData = () => { const start = currentIndex.value * props.pageSize; const end = start + props.pageSize; currentData.value = props.data.slice(start, end); }; const calculateShowPrevBtn = () => { showPrevBtn.value = currentIndex.value !== 0; }; const calculateShowNextBtn = () => { showNextBtn.value = currentIndex.value !== totalPage.value - 1; }; const handlePrevClick = () => { currentIndex.value--; }; const handleNextClick = () => { currentIndex.value++; }; const handleItemClick = (index: number) => { if (currentIndex.value === totalPage.value - 1 && index === props.data.length - 1) { currentDetailIndex.value = index; showDetail.value = true; } }; const handleTouchStart = (event: TouchEvent) => { // TODO: 记录起始位置 }; const handleTouchMove = (event: TouchEvent) => { // TODO: 计算滑动距离并更新列表位置 }; watchEffect(() => { calculateTotalPage(); calculateCurrentData(); calculateShowPrevBtn(); calculateShowNextBtn(); }); return { currentIndex, currentDetailIndex, showPrevBtn, showNextBtn, showDetail, totalPage, currentData, position, handlePrevClick, handleNextClick, handleItemClick, handleTouchStart, handleTouchMove, }; }, }); </script> <style scoped> .horizontal-list { position: relative; height: 100%; overflow: hidden; .list-wrapper { display: flex; flex-direction: row; transition: transform 0.3s ease-in-out; } .list-item { flex: 0 0 calc(100% / 3); height: 100%; display: flex; align-items: center; justify-content: center; font-size: 24px; border-right: 1px solid #ccc; } .detail { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background-color: rgba(0, 0, 0, 0.5); color: #fff; font-size: 36px; z-index: 1; } .pagination { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); display: flex; justify-content: center; margin-bottom: 16px; button { margin-left: 16px; } } } </style> ``` 以上代码仅供参考,具体实现可以根据实际需求进行调整。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Embrace924

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值