mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2025-05-21 20:32:44 +08:00
fix scroll-reveal-component problems
This commit is contained in:
parent
2e63c1df5e
commit
862f357340
@ -6,29 +6,56 @@ const RayScrollReveal = defineComponent({
|
|||||||
name: 'RayScrollReveal',
|
name: 'RayScrollReveal',
|
||||||
props: {
|
props: {
|
||||||
options: {
|
options: {
|
||||||
|
// ScrollReveal reveal options
|
||||||
type: Object as PropType<scrollReveal.ScrollRevealObjectOptions>,
|
type: Object as PropType<scrollReveal.ScrollRevealObjectOptions>,
|
||||||
},
|
},
|
||||||
|
width: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
reset: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
emits: ['scrollRevealSync'],
|
emits: ['scrollRevealSync'],
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
const scrollRevealRef = ref<HTMLElement>()
|
const scrollRevealRef = ref<HTMLElement>()
|
||||||
|
const cssVarsRef = computed(() => {
|
||||||
|
const scsVars = {
|
||||||
|
'--ray-scroll-reveal-width': props.width,
|
||||||
|
}
|
||||||
|
|
||||||
|
return scsVars
|
||||||
|
})
|
||||||
|
let scrollRevealCore: scrollReveal.ScrollRevealObject
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 为 `dom` 注册 `ScrollReveal` 动画效果
|
||||||
|
*/
|
||||||
const handleRegisterScrollReveal = async () => {
|
const handleRegisterScrollReveal = async () => {
|
||||||
const el = scrollRevealRef.value as HTMLElement
|
const el = scrollRevealRef.value as HTMLElement
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
distance: '50px',
|
distance: '50px',
|
||||||
duration: 600,
|
duration: 600,
|
||||||
reset: true,
|
reset: props.reset,
|
||||||
easing: 'ease',
|
easing: 'ease',
|
||||||
scale: 0.99,
|
scale: 0.99,
|
||||||
mobile: true,
|
mobile: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollReveal().reveal(el, Object.assign(defaultOptions, props.options))
|
scrollRevealCore = ScrollReveal().reveal(
|
||||||
|
el,
|
||||||
|
Object.assign(defaultOptions, props.options),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 处理 `dom` 新增后无法绑定过渡动画情况
|
||||||
|
*/
|
||||||
const handleScrollRevealSync = async () => {
|
const handleScrollRevealSync = async () => {
|
||||||
const { sync } = ScrollReveal()
|
const { sync } = scrollRevealCore
|
||||||
|
|
||||||
emit('scrollRevealSync', sync)
|
emit('scrollRevealSync', sync)
|
||||||
}
|
}
|
||||||
@ -40,11 +67,16 @@ const RayScrollReveal = defineComponent({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
scrollRevealRef,
|
scrollRevealRef,
|
||||||
|
cssVarsRef,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div class="ray-scroll-reveal" ref="scrollRevealRef">
|
<div
|
||||||
|
class="ray-scroll-reveal"
|
||||||
|
ref="scrollRevealRef"
|
||||||
|
style={this.cssVarsRef}
|
||||||
|
>
|
||||||
{this.$slots.default?.()}
|
{this.$slots.default?.()}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user