动画
This commit is contained in:
@@ -87,7 +87,7 @@ function add(el, root = document) {
|
|||||||
obj.observer.observe(el)
|
obj.observer.observe(el)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resize.observe(root)
|
resize.observe(isDocumentRoot(root))
|
||||||
root.addEventListener('scroll', handleScroll)
|
root.addEventListener('scroll', handleScroll)
|
||||||
const observer = new IntersectionObserver((entries) => {
|
const observer = new IntersectionObserver((entries) => {
|
||||||
entries.forEach((entry) => {
|
entries.forEach((entry) => {
|
||||||
@@ -112,7 +112,7 @@ function remove(el, root = document) {
|
|||||||
}
|
}
|
||||||
if (obj.els.length === 0) {
|
if (obj.els.length === 0) {
|
||||||
obj.observer.disconnect()
|
obj.observer.disconnect()
|
||||||
resize.unobserve(root)
|
resize.unobserve(isDocumentRoot(root))
|
||||||
root.removeEventListener('scroll', handleScroll)
|
root.removeEventListener('scroll', handleScroll)
|
||||||
roots.delete(root)
|
roots.delete(root)
|
||||||
}
|
}
|
||||||
@@ -130,9 +130,10 @@ async function handleScroll({ target: root }) {
|
|||||||
if (!item.scroll) return
|
if (!item.scroll) return
|
||||||
const children = el.querySelectorAll(typesStr)
|
const children = el.querySelectorAll(typesStr)
|
||||||
if (children.length === 0) return
|
if (children.length === 0) return
|
||||||
const elTop_bottom = root.offsetHeight - (el.offsetTop - root.offsetTop - root.scrollTop)
|
const rootEl = isDocumentRoot(root)
|
||||||
const maxHeight = root.offsetHeight + el.offsetHeight
|
const elTop_bottom = rootEl.offsetHeight - (el.offsetTop - rootEl.offsetTop - rootEl.scrollTop)
|
||||||
const p = Math.min(1, Math.max(0, elTop_bottom / maxHeight))
|
const maxHeight = rootEl.offsetHeight + el.offsetHeight
|
||||||
|
const p = Math.min(1, Math.max(0, elTop_bottom / maxHeight))
|
||||||
children.forEach((item) => {
|
children.forEach((item) => {
|
||||||
item.style.transition = 'transform 0.5s ease-out'
|
item.style.transition = 'transform 0.5s ease-out'
|
||||||
|
|
||||||
@@ -165,4 +166,8 @@ function hasAttr(el, attr) {
|
|||||||
} else {
|
} else {
|
||||||
return el.hasAttribute(attr)
|
return el.hasAttribute(attr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 检查document是否为根元素
|
||||||
|
function isDocumentRoot(root) {
|
||||||
|
return root === document ? document.documentElement : root
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ import type { App } from 'vue'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
install(app: App) {
|
install(app: App) {
|
||||||
const directivesList = import.meta.glob('./*.ts', { eager: true }) as any;
|
const directivesList1 = import.meta.glob('./*.ts', { eager: true }) as any;
|
||||||
|
const directivesList2 = import.meta.glob('./*.js', { eager: true }) as any;
|
||||||
|
const directivesList = { ...directivesList1, ...directivesList2 };
|
||||||
Object.keys(directivesList).forEach(key => {
|
Object.keys(directivesList).forEach(key => {
|
||||||
app.directive(directivesList[key].default.name, directivesList[key].default);
|
app.directive(directivesList[key].default.name, directivesList[key].default);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,13 +18,15 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<section class="product-feature" :class="{ 'product-feature-reversed': reversed }">
|
<section class="product-feature" :class="{ 'product-feature-reversed': reversed }" v-custom-animation.scroll>
|
||||||
<div class="product-feature-art">
|
<div class="product-feature-art">
|
||||||
<img
|
<img
|
||||||
class="product-feature-bg"
|
class="product-feature-bg"
|
||||||
:src="backgroundImage"
|
:src="backgroundImage"
|
||||||
:alt="backgroundAlt"
|
:alt="backgroundAlt"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
|
translate-x-s="-100"
|
||||||
|
translate-x="100"
|
||||||
/>
|
/>
|
||||||
<img class="product-feature-panel" :src="panelImage" :alt="panelAlt" loading="lazy" />
|
<img class="product-feature-panel" :src="panelImage" :alt="panelAlt" loading="lazy" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user