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 @@