Skip to Content
📣 We just released Svelte Flow 1.0 Alpha — try it out and give us your feedback!
ExamplesInteractionContextual Zoom

Contextual Zoom

This example shows how the current zoom level can be used by a node to decide which content to show. We can access the zoom inside the viewport writable via the useSvelteStore hook to update our custom node whenever the zoom changes.

<script lang="ts"> import { SvelteFlow, Background, type Node, type Edge } from '@xyflow/svelte'; import '@xyflow/svelte/dist/style.css'; import { initialNodes, initialEdges } from './nodes-and-edges'; import ZoomNode from './ZoomNode.svelte'; let nodes = $state.raw<Node[]>(initialNodes); let edges = $state.raw<Edge[]>(initialEdges); const nodeTypes = { zoom: ZoomNode, }; </script> <div style="height:100vh;"> <SvelteFlow bind:nodes {nodeTypes} bind:edges fitView> <Background /> </SvelteFlow> </div>
⚠️
To surpress unknown prop warnings in the browser console, please refer to the guide.
Last updated on