Guide

Heavy views

A view with thousands of nodes, or with frosted glass, is costly to scale and blur on every frame. flatten keeps a photo of the view you are in, with SnapDOM, and moves the photo while the view sits behind. Zoom into a bright tile with it on, then off.

Live exampleOpen ↗

Turn it on

Install SnapDOM and its plugins next to Zumly, and hand over snapdom and stream:

npm install zumly @zumer/snapdom @zumer/snapdom-plugins
import Zumly from 'zumly'
import { snapdom } from '@zumer/snapdom'
import { stream } from '@zumer/snapdom-plugins/stream'

new Zumly({ mount: '.canvas', initialView: 'home', views, flatten: { snapdom, stream } })

Both are optional peer dependencies: npm install zumly alone does not bring them. Without a bundler, import them from a CDN, as the example does. If SnapDOM is missing, Zumly says so once in the console and the views stay as they are.

What happens

When it pays off

Three zooms in and three out, with a clock, spinners and numbers changing in every view. Chrome on a MacBook; a dropped frame is one the screen never got.

ViewsWithoutanimateEffects: falseWith flatten
Cards, about 3,000 nodes6.8% dropped5.2%1.3%, no hitch
Frosted glass52% dropped, 48% at rest48%, 48% at rest0%, 0% at rest
Orbit dials (light)0.6%0%left alone

With the processor four times slower, frosted glass drops 47% without and 0.6% with flatten.

A light view gains nothing, so flatten leaves it alone. It photographs a view with at least minNodes elements, or with backdrop-filter inside. Mark a view data-flatten="true" to photograph it anyway, or data-flatten="false" to keep it live behind (a video, a game). Views with an iframe stay live: SnapDOM can only draw a placeholder for it.

Options

OptionDefaultDescription
snapdomthe global snapdomThe snapdom function from @zumer/snapdom.
streamnoneThe stream function from @zumer/snapdom-plugins/stream. It keeps the photo current; without it, only views that hold still are flattened.
minNodes800Views with fewer elements are photographed only if they use backdrop-filter.
scale1Resolution of the photo. The blur behind hides its softness; without effects, 2 keeps text behind sharp, for four times the memory.

Good to know

Try the cheap fix first

transitions: { animateEffects: false } applies the blur at once instead of animating it. It needs nothing else, and with many nodes it already takes out part of the stutter. Reach for flatten when that is not enough: frosted glass, thousands of nodes, or a slow device.