Skip to main content

Reflex custom component intersection-observer

Project description

intersection-observer

React to a component coming into view using Reflex event handler.

Installation

pip install reflex-intersection-observer

Usage

import reflex as rx

from reflex_intersection_observer import intersection_observer

def index():
    return rx.vstack(
        rx.box(height="150vh"), 
        intersection_observer(
            on_intersect=rx.console_log,
        ),
    )

See intersection_observer_demo app for further examples.

Props

The following props are understood by intersection_observer:

  • root - ID of the element that is used as the viewport for checking visibility of the target. Must be the id of a parent of the target. Default is the browser viewport.
  • root_margin - An offset rectangle applied to the root's bounding box when calculating intersections, effectively shrinking or growing the root for calculation purposes. The value returned by this property may not be the same as the one specified when calling the constructor as it may be changed to match internal requirements. Each offset can be expressed in pixels (px) or as a percentage (%). The default is "0px 0px 0px 0px".
  • threshold - value between 0 and 1 indicating the percentage that should be visible before the event is triggered. Default is 1.

The following events are emitted by intersection_observer:

  • on_intersect - fired when the target element intersects with the root element.
  • on_non_intersect - fired when the target element does not intersect with the root element.

Both of these events provide an IntersectionObserverEntry with intersection details:

  • intersection_ratio: how much of the target element is intersection (0 - 1).
  • is_intersecting: true/false based on whether the observer is intersecting or not
  • time: relative timestamp when the intersection occurred

See IntersectionObserver API docs on MDN for more information about how the API works.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reflex_intersection_observer-0.0.9.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reflex_intersection_observer-0.0.9-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file reflex_intersection_observer-0.0.9.tar.gz.

File metadata

  • Download URL: reflex_intersection_observer-0.0.9.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for reflex_intersection_observer-0.0.9.tar.gz
Algorithm Hash digest
SHA256 8f398db49b21bc048311ff50b8e7857125be2dcab6498c0150b927a4af161989
MD5 d0aaabc65cdf8e39c90294dc15d93417
BLAKE2b-256 916fa98f51727e4ea3e7f242887c08032b037bee24cb45359b55974154e53854

See more details on using hashes here.

File details

Details for the file reflex_intersection_observer-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: reflex_intersection_observer-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for reflex_intersection_observer-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 20e68ccdad80b397a72e1b4c31ab4f8b1bd234b88008479d5db395019ad57017
MD5 5bfbe4d78660e98f306b82ab5ed1ae63
BLAKE2b-256 603dc98f0815195c60af022b9067b04c5d44c07141779c0654fc8944ccca46df

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page