<template>
<div ref="scrollWrapper" class="scroll" style="height: 100%">
<div
:class="{ 'list-item-wrapper': isShowScroll }"
:style="{
animationDuration: carouselSpeed * InnerHeight + 's',
}"
>
<div ref="scrollInner">
<div v-for="(item, index) in dataList" :key="index">
{{ item.name }}
</div>
</div>
<div v-html="copyHtml"></div>
</div>
</div>
</template>
<script lang="ts" setup>
import { nextTick, ref, watch } from "vue";
const props = defineProps({
carouselSpeed: {
type: Number,
default: 0.02,
},
// 组件外部传进来的数据
progressData: {
type: Object,
default: () => [],
},
});
const scrollInner = ref<any>();
const scrollWrapper = ref<any>();
const InnerHeight = ref(0);
const scrollHeight = ref(0);
const copyHtml = ref("");
const isShowScroll = ref(false);
const dataList = ref<any>([]);
watch(
() => props.progressData,
(val) => {
dataList.value = val;
nextTick(() => {
InnerHeight.value = getStyleHeight(scrollInner.value);
scrollHeight.value = getStyleHeight(scrollWrapper.value);
isShowScroll.value = isNeedScroll(scrollHeight.value, InnerHeight.value);
copyHtml.value = isShowScroll.value
? (scrollInner.value as unknown as any).innerHTML
: "";
});
},
{
deep: true,
}
);
const getStyleHeight = (el: any) => {
return el.offsetHeight;
};
const isNeedScroll = (height: any, children: any) => {
const containerHeight = height;
const childrenHeight = children;
return childrenHeight > containerHeight;
};
</script>
<style scoped>
.scroll {
overflow: hidden;
}
.list-item-wrapper {
-webkit-animation: move 10s linear infinite;
animation: move 10s linear infinite;
}
.list-item-wrapper:hover {
animation-play-state: paused;
}
@keyframes move {
0% {
transform: translateY(0);
}
100% {
transform: translateY(-50%);
}
}
</style>
基于vue3实现的列表无限滚动组件
需积分: 5 121 浏览量
2023-10-18
16:56:09
上传
评论
收藏 1KB ZIP 举报
大兵的猫
- 粉丝: 64
- 资源: 5
最新资源
- 设计1.ms14
- vscode-1.64.1.tar源码文件
- vscode-1.64.0.tar源码文件
- vscode-1.52.0.tar源码文件
- Music-Player +PlayerActivity+ rockplayer+ SeeJoPlayer 播放器JAVA源码
- vscode-1.46.0.tar源码文件
- 最近很火植物大战僵尸杂交版2.08苹果+安卓+PC+防闪退工具V2+修改工具+高清工具+通关存档整合包更新
- 超级好用的截图工具PixPin,可录制Gif图
- Screenshot_2024-05-21-17-06-42-64_2332cb9b27b851b548ba47a91682926c.jpg
- 毕业设计参考 - 基于树莓派、OpenCV及Python的人脸识别
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈