From 96616b9406ccc572c5c6eea31ac102fbda73a518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=90=A6?= Date: Sat, 1 Aug 2026 09:48:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A1=B5=E9=9D=A2=E6=95=88?= =?UTF-8?q?=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/PhotoGallery.vue | 3 +- vite-tailwindcss/src/directives/reveal.js | 17 ++++- vite-tailwindcss/src/views/index/index.vue | 67 ++++++++----------- 3 files changed, 45 insertions(+), 42 deletions(-) diff --git a/vite-tailwindcss/src/components/PhotoGallery.vue b/vite-tailwindcss/src/components/PhotoGallery.vue index bb0452d..7bee8a1 100644 --- a/vite-tailwindcss/src/components/PhotoGallery.vue +++ b/vite-tailwindcss/src/components/PhotoGallery.vue @@ -37,7 +37,8 @@ -
+ +
diff --git a/vite-tailwindcss/src/directives/reveal.js b/vite-tailwindcss/src/directives/reveal.js index e1001ab..11cdf96 100644 --- a/vite-tailwindcss/src/directives/reveal.js +++ b/vite-tailwindcss/src/directives/reveal.js @@ -1,5 +1,3 @@ -import { ref, onMounted, onUnmounted } from 'vue' - /** * v-reveal 滚动入场指令 * @@ -28,6 +26,19 @@ function parseBinding(value) { } } +function findScrollRoot(el) { + let parent = el.parentElement + while (parent && parent !== document.body) { + const style = window.getComputedStyle(parent) + const overflowY = style.overflowY + if ((overflowY === 'auto' || overflowY === 'scroll') && parent.scrollHeight > parent.clientHeight) { + return parent + } + parent = parent.parentElement + } + return null +} + const reveal = { mounted(el, binding) { const { variant, delay } = parseBinding(binding.value) @@ -43,7 +54,7 @@ const reveal = { observer.unobserve(el) } }, - { threshold: 0.12, rootMargin: '0px 0px -8% 0px' } + { threshold: 0.12, root: findScrollRoot(el), rootMargin: '0px 0px -8% 0px' } ) observer.observe(el) el.__revealObserver = observer diff --git a/vite-tailwindcss/src/views/index/index.vue b/vite-tailwindcss/src/views/index/index.vue index 01e626c..8fb00cd 100644 --- a/vite-tailwindcss/src/views/index/index.vue +++ b/vite-tailwindcss/src/views/index/index.vue @@ -1,5 +1,5 @@