Function useAnchorPosition

  • Positions a target element around the anchor element.

    Parameters

    Returns void

    const anchorRef = useRef(null);
    const targetRef = useRef(null);

    useAnchorPosition({
    getAnchorRect: () => anchorRef.current.getBoundingClientRect(),
    getTargetRect: () => targetRef.current.getBoundingClientRect(),
    variants: [
    {
    alignX: 'outerEnd',
    alignY: 'center',
    },
    ],
    onPositionChange(info) {
    targetRef.current.style.transform = `translateX(${info.x}px) translateY(${info.y}px)`;
    },
    });

    <div ref={anchorRef} />
    <div
    ref={targetRef}
    style={{ position: 'fixed' }}
    />