From fc3e60e94c9f7c0a3e8a277fe4178d218ce3b6a7 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Mon, 18 Mar 2024 13:36:07 +0800 Subject: [PATCH] =?UTF-8?q?movie=20=E4=B8=BB=E9=A2=98=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=8C=E5=A4=96=E9=93=BE=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E5=88=86=E9=9B=86=E7=9C=81=E6=B5=81=EF=BC=9B=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=9A=82=E5=81=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/movie/index.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/themes/movie/index.js b/themes/movie/index.js index d7c08bb6..326781e1 100644 --- a/themes/movie/index.js +++ b/themes/movie/index.js @@ -194,10 +194,20 @@ const LayoutSlug = props => { const carouselItem = document.createElement('div') carouselItem.classList.add('notion-carousel') carouselItem.appendChild(wrapper) + + // 如有外链、保存在data-src中 + const iframe = wrapper.querySelector('iframe') + if (iframe) { + iframe.setAttribute('data-src', iframe.getAttribute('src')) + } + // 如果是第一个元素,设置为 active if (index === 0) { carouselItem.classList.add('active') + } else { + iframe.setAttribute('src', '') } + // 将元素添加到容器中 carouselWrapper.appendChild(carouselItem) // 从 DOM 中移除原始的 .notion-asset-wrapper 元素 @@ -215,15 +225,26 @@ const LayoutSlug = props => { div.addEventListener('click', function () { // 遍历所有的 carouselItem 元素 document.querySelectorAll('.notion-carousel').forEach(item => { + // 外链保存在data-src中 + const iframe = item.querySelector('iframe') + console.log('iframe', iframe.getAttribute('data-src'), iframe.getAttribute('src')) + // 判断当前元素是否包含该 figCaption 的文本内容,如果是则设置为 active,否则取消 active if (item.querySelector('figcaption').textContent.trim() === value) { item.classList.add('active') + if (iframe) { + iframe.setAttribute('src', iframe.getAttribute('data-src')) + } } else { item.classList.remove('active') // 不活跃窗口暂停播放,仅支持notion上传视频、不支持外链 item.querySelectorAll('video')?.forEach(video => { video.pause() }) + // 外链通过设置src来实现视频暂停播放 + if (iframe) { + iframe.setAttribute('src', '') + } } }) })