hookehuyr

播放位移到指定高度

...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
8 <van-icon @click="onClose" name="cross" color="#DD7850" size="1.25rem" /> 8 <van-icon @click="onClose" name="cross" color="#DD7850" size="1.25rem" />
9 </div> 9 </div>
10 </template> 10 </template>
11 - <div class="van-hairline--top" style="padding: 1rem;"> 11 + <div class="audio-list van-hairline--top" style="padding: 1rem;">
12 - <div v-for="(item, index) in audio_list" :key="index" class="van-hairline--bottom audio-item"> 12 + <div :id="index" v-for="(item, index) in audio_list" :key="index" class="van-hairline--bottom audio-item">
13 <div :class="['point', audio_index === index ? 'checked' : '']"></div> 13 <div :class="['point', audio_index === index ? 'checked' : '']"></div>
14 <div :class="['text', audio_index === index ? 'checked' : '', 'van-ellipsis']" @click="toggleHandleAudio(item, index)"> 14 <div :class="['text', audio_index === index ? 'checked' : '', 'van-ellipsis']" @click="toggleHandleAudio(item, index)">
15 {{ index + 1 }}. {{ item.title }}<span v-if="item.play" class="text-center">正在播放</span> 15 {{ index + 1 }}. {{ item.title }}<span v-if="item.play" class="text-center">正在播放</span>
...@@ -58,6 +58,15 @@ const onHeightChange = ({ height }) => { // 监听高度变化 ...@@ -58,6 +58,15 @@ const onHeightChange = ({ height }) => { // 监听高度变化
58 if (!height) { // 关闭 58 if (!height) { // 关闭
59 onClose(); 59 onClose();
60 } 60 }
61 + // 打开列表高度需要删除底部滚动空间
62 + if (height > (0.2 * window.innerHeight)) {
63 + $('.audio-list').css('marginBottom', 0);
64 + }
65 + // 添加可滚动高度
66 + if (height === (0.2 * window.innerHeight)) {
67 + let str = $('.audio-item').height() * audio_list.value.length;
68 + $('.audio-list').css('marginBottom', `${str}px`);
69 + }
61 } 70 }
62 71
63 const info_height = ref(0); 72 const info_height = ref(0);
...@@ -72,6 +81,9 @@ watch( ...@@ -72,6 +81,9 @@ watch(
72 if (v) { 81 if (v) {
73 // 自动打开第一个 82 // 自动打开第一个
74 handleAudioPlay(audio_list.value[0], 0); 83 handleAudioPlay(audio_list.value[0], 0);
84 + // 添加可滚动高度
85 + let str = $('.audio-item').height() * audio_list.value.length;
86 + $('.audio-list').css('marginBottom', `${str}px`);
75 } else { 87 } else {
76 onClose(); 88 onClose();
77 } 89 }
...@@ -239,6 +251,20 @@ const handleAudioPlay = (item, index) => { ...@@ -239,6 +251,20 @@ const handleAudioPlay = (item, index) => {
239 console.log('Operation is too fast, audio play fails') 251 console.log('Operation is too fast, audio play fails')
240 }) 252 })
241 } 253 }
254 + if (index) {
255 + // 指定滚动到播放位置
256 + scrollToId(index);
257 + }
258 +}
259 +
260 +const scrollToId = (index) => { // 滚动到指定元素
261 + nextTick(() => {
262 + const element = document.getElementById(index);
263 + console.warn(element);
264 + if (element) {
265 + element.scrollIntoView({ behavior: "smooth", block: "start" });
266 + }
267 + })
242 } 268 }
243 269
244 const voicePause = () => { 270 const voicePause = () => {
......