createInView
Returns a boolean accessor that changes when the target enters or leaves the viewport or a custom
root. Use whileInView for visual state on a motion.* element; use createInView when the
visibility state needs to drive other logic.
import { createInView } from 'motion-solidjs'
import { createSignal, createEffect } from 'solid-js'
function Section() {
const [el, setEl] = createSignal<HTMLElement | null>(null)
const inView = createInView(el, { amount: 0.5, once: true })
createEffect(() => {
if (inView()) trackImpression()
})
return <section ref={setEl}>{/* content */}</section>
}
scroll to test
Options
root- accessor returning the scroll rootmargin-IntersectionObserverroot marginamount-'some' | 'all' | number(0-1), controlling how much must be visibleonce- stop observing after the first entry