滚动
Showing
2 changed files
with
157 additions
and
3 deletions
| ... | @@ -13,8 +13,10 @@ | ... | @@ -13,8 +13,10 @@ |
| 13 | <div><img alt="" class="rTop-img" src="@/assets/image/more@2x.png"></div> | 13 | <div><img alt="" class="rTop-img" src="@/assets/image/more@2x.png"></div> |
| 14 | </div> | 14 | </div> |
| 15 | <div class="rBotton"> | 15 | <div class="rBotton"> |
| 16 | <div class="row-text"><span/> 这里是文案内容这里是文案内容这里是文案内容</div> | 16 | |
| 17 | <div class="row-text"><span/> 这里是文案内容这里是文案内容这里是文案内容</div> | 17 | <ScrollingData :data="dataItems" speed="1"/> |
| 18 | <!-- <div class="row-text"><span/> 这里是文案内容这里是文案内容这里是文案内=容</div>--> | ||
| 19 | <!-- <div class"row-text"><span/> 这里是文案内容这里是文案内容这里是文案内容</div>--> | ||
| 18 | <!-- <div class="row-text"><span/> 这里是文案内容这里是文案内容这里是文案内容</div>--> | 20 | <!-- <div class="row-text"><span/> 这里是文案内容这里是文案内容这里是文案内容</div>--> |
| 19 | <!-- <div class="row-text"><span/> 这里是文案内容这里是文案内容这里是文案内容</div>--> | 21 | <!-- <div class="row-text"><span/> 这里是文案内容这里是文案内容这里是文案内容</div>--> |
| 20 | <!-- <div class="row-text"><span/> 这里是文案内容这里是文案内容这里是文案内容</div>--> | 22 | <!-- <div class="row-text"><span/> 这里是文案内容这里是文案内容这里是文案内容</div>--> |
| ... | @@ -98,10 +100,28 @@ | ... | @@ -98,10 +100,28 @@ |
| 98 | 100 | ||
| 99 | <script setup> | 101 | <script setup> |
| 100 | import {autoToolTip} from "@/plugins/auto-toolTip"; | 102 | import {autoToolTip} from "@/plugins/auto-toolTip"; |
| 103 | import ScrollingData from './scrollingData .vue' | ||
| 101 | import * as echarts from "echarts"; | 104 | import * as echarts from "echarts"; |
| 102 | import * as api from "@/apiPc/common" | 105 | import * as api from "@/apiPc/common" |
| 103 | import {onMounted, ref} from 'vue' | 106 | import {onMounted, ref} from 'vue' |
| 104 | 107 | ||
| 108 | |||
| 109 | const dataItems = ref([ | ||
| 110 | '数据项 1: 当前值 256', | ||
| 111 | '数据项 2: 当前值 189', | ||
| 112 | '数据项 3: 当前值 342', | ||
| 113 | '数据项 4: 当前值 127', | ||
| 114 | '数据项 5: 当前值 298', | ||
| 115 | '数据项 6: 当前值 431', | ||
| 116 | '数据项 7: 当前值 156', | ||
| 117 | '数据项 8: 当前值 321', | ||
| 118 | '数据项 9: 当前值 456', | ||
| 119 | '数据项 10: 当前值 234', | ||
| 120 | '数据项 11: 当前值 321', | ||
| 121 | '数据项 12: 当前值 456', | ||
| 122 | '数据项 13: 当前值 234', | ||
| 123 | '数据项 14: 当前值 321', | ||
| 124 | ]); | ||
| 105 | const zhuRef1 = ref(null) | 125 | const zhuRef1 = ref(null) |
| 106 | const zhuRef2 = ref(null) | 126 | const zhuRef2 = ref(null) |
| 107 | const zhuRef3 = ref(null) | 127 | const zhuRef3 = ref(null) |
| ... | @@ -999,7 +1019,7 @@ function autoHover(myChart, option, index, time) { | ... | @@ -999,7 +1019,7 @@ function autoHover(myChart, option, index, time) { |
| 999 | } | 1019 | } |
| 1000 | 1020 | ||
| 1001 | .rBotton { | 1021 | .rBotton { |
| 1002 | height: calc(60 * 100vw / 1920); | 1022 | height: calc(130 * 100vh / 1920); |
| 1003 | //overflow-y: scroll; | 1023 | //overflow-y: scroll; |
| 1004 | .row-text { | 1024 | .row-text { |
| 1005 | font-family: PingFang SC, serif; | 1025 | font-family: PingFang SC, serif; | ... | ... |
src/viewsPc/vip/scrollingData .vue
0 → 100644
| 1 | <template> | ||
| 2 | <div class="scrolling-container" @mouseenter="pauseScroll" @mouseleave="resumeScroll"> | ||
| 3 | <div :style="{ transform: `translateY(${offset}px)` }" class="scrolling-content"> | ||
| 4 | <div v-for="(item, index) in dataList" :key="index" class="scrolling-item"> | ||
| 5 | <span/> {{ item }} | ||
| 6 | </div> | ||
| 7 | <!-- 复制一份数据实现无缝滚动 --> | ||
| 8 | <div v-for="(item, index) in dataList" :key="`copy-${index}`" class="scrolling-item"> | ||
| 9 | <span/> {{ item }} | ||
| 10 | </div> | ||
| 11 | </div> | ||
| 12 | </div> | ||
| 13 | </template> | ||
| 14 | |||
| 15 | <script setup> | ||
| 16 | import {ref, onMounted, onUnmounted} from 'vue'; | ||
| 17 | |||
| 18 | const props = defineProps({ | ||
| 19 | data: { | ||
| 20 | type: Array, | ||
| 21 | required: true | ||
| 22 | }, | ||
| 23 | speed: { | ||
| 24 | type: Number, | ||
| 25 | default: 1 // 滚动速度,数值越大越快 | ||
| 26 | }, | ||
| 27 | delay: { | ||
| 28 | type: Number, | ||
| 29 | default: 1000 // 初始延迟时间(毫秒) | ||
| 30 | } | ||
| 31 | }); | ||
| 32 | |||
| 33 | const dataList = ref([...props.data]); | ||
| 34 | const offset = ref(0); | ||
| 35 | const scrollInterval = ref(null); | ||
| 36 | const isPaused = ref(false); | ||
| 37 | const containerHeight = ref(0); | ||
| 38 | const contentHeight = ref(0); | ||
| 39 | const itemHeight = ref(0); | ||
| 40 | |||
| 41 | // 初始化滚动 | ||
| 42 | const initScroll = () => { | ||
| 43 | // 清除之前的定时器 | ||
| 44 | if (scrollInterval.value) { | ||
| 45 | clearInterval(scrollInterval.value); | ||
| 46 | } | ||
| 47 | // 重置位置到第一条数据 | ||
| 48 | offset.value = 0; | ||
| 49 | |||
| 50 | // 设置定时器 | ||
| 51 | scrollInterval.value = setInterval(() => { | ||
| 52 | if (!isPaused.value) { | ||
| 53 | offset.value -= props.speed; | ||
| 54 | // 当滚动到内容的一半时,重置位置实现无缝滚动 | ||
| 55 | if (Math.abs(offset.value) >= contentHeight.value / 2) { | ||
| 56 | offset.value += contentHeight.value / 2; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | }, 20); | ||
| 60 | }; | ||
| 61 | |||
| 62 | // 暂停滚动 | ||
| 63 | const pauseScroll = () => { | ||
| 64 | isPaused.value = true; | ||
| 65 | }; | ||
| 66 | |||
| 67 | // 恢复滚动 | ||
| 68 | const resumeScroll = () => { | ||
| 69 | isPaused.value = false; | ||
| 70 | }; | ||
| 71 | |||
| 72 | onMounted(() => { | ||
| 73 | // 延迟启动滚动,确保DOM已渲染 | ||
| 74 | setTimeout(() => { | ||
| 75 | const container = document.querySelector('.scrolling-container'); | ||
| 76 | const content = document.querySelector('.scrolling-content'); | ||
| 77 | const firstItem = document.querySelector('.scrolling-item'); | ||
| 78 | |||
| 79 | if (container && content && firstItem) { | ||
| 80 | containerHeight.value = container.clientHeight; | ||
| 81 | contentHeight.value = content.clientHeight; | ||
| 82 | itemHeight.value = firstItem.clientHeight; | ||
| 83 | |||
| 84 | // 如果内容高度小于容器高度,不需要滚动 | ||
| 85 | if (contentHeight.value > containerHeight.value) { | ||
| 86 | // 初始位置设置为显示第一条数据 | ||
| 87 | // offset.value = 0; | ||
| 88 | initScroll(); | ||
| 89 | } | ||
| 90 | } | ||
| 91 | }, props.delay); | ||
| 92 | }); | ||
| 93 | |||
| 94 | onUnmounted(() => { | ||
| 95 | if (scrollInterval.value) { | ||
| 96 | clearInterval(scrollInterval.value); | ||
| 97 | } | ||
| 98 | }); | ||
| 99 | </script> | ||
| 100 | |||
| 101 | <style scoped> | ||
| 102 | .scrolling-container { | ||
| 103 | width: 100%; | ||
| 104 | height: 100%; | ||
| 105 | overflow: hidden; | ||
| 106 | position: relative; | ||
| 107 | } | ||
| 108 | |||
| 109 | .scrolling-content { | ||
| 110 | transition: transform 0.1s ease; | ||
| 111 | will-change: transform; | ||
| 112 | } | ||
| 113 | |||
| 114 | .scrolling-item { | ||
| 115 | font-family: PingFang SC, serif; | ||
| 116 | font-weight: 400; | ||
| 117 | font-size: calc(17 * 100vw / 1920); | ||
| 118 | color: #FFFFFF; | ||
| 119 | height: calc(40 * 100vh / 1920); | ||
| 120 | margin: calc(8 * 100vw / 1920) 0; | ||
| 121 | |||
| 122 | span { | ||
| 123 | display: inline-block; | ||
| 124 | width: calc(12 * 100vw / 1920); | ||
| 125 | height: calc(12 * 100vw / 1920); | ||
| 126 | background-color: #01D7F0; | ||
| 127 | transform: rotate(45deg); | ||
| 128 | margin-left: calc(3 * 100vw / 1920); | ||
| 129 | border-radius: calc(3 * 100vw / 1920); | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | |||
| 134 | </style> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment