Motion and gestures
Tune how a zoom feels, and let a gesture drive the zoom-out as it moves.
Bubble 2 has its own duration. To go back slowly: on a phone, swipe left or pinch; on a laptop, scroll with two fingers. The line at the bottom shows the gesture’s progress.
The code
const bubble = name => `<div class="z-view big" data-title="${name}"><h2>${name}</h2><p>Swipe left, pinch<br>or scroll to go back.</p></div>`
const app = new Zumly({
mount: '.canvas',
initialView: 'deep',
views: {
deep: `<div class="z-view deep" data-title="The deep">
<p>Pick a bubble</p>
<div class="bubbles">
<div class="zoom-me bubble" data-to="one">1</div>
<div class="zoom-me bubble" data-to="two" data-with-duration="1.6s">2</div>
<div class="zoom-me bubble" data-to="three">3</div>
</div>
</div>`,
one: bubble('One'),
two: bubble('Two, slowly'),
three: bubble('Three')
},
transitions: {
duration: '900ms',
ease: 'cubic-bezier(.2,.8,.2,1)',
effects: ['blur(3px) brightness(.6)', 'blur(8px) brightness(.3)'],
hideTrigger: 'fade'
},
// Zoom-out follows the trackpad, a swipe or a pinch as it moves
gestures: { follow: true, threshold: 0.4 },
inputs: { pinch: true },
lateralNav: false
})
// The gesture's progress, from 0 to 1
const meter = document.querySelector('.meter')
app.on('zoomOutProgress', ({ phase, progress }) => {
meter.style.width = phase === 'end' ? '0' : progress * 100 + '%'
})
app.init()
Transitions
durationandeaseset the timing;effectsare CSS filters for the two views behind the current one.blur()is the expensive one: on large, busy views it drops frames while they move, so preferbrightness()andsaturate()there (the showcases do), or setanimateEffects: false.hideTrigger: 'fade'crossfades the trigger into the new view.- Any trigger can override them:
data-with-duration,data-with-ease,data-with-effects. - With
prefers-reduced-motion, transitions are instant.
Gestures
gestures: { follow: true }makes the trackpad, a swipe and a pinch move the views as they go. Releasing pastthresholdfinishes the zoom-out; otherwise everything returns.inputs: { pinch: true }adds closing two fingers. It is off by default because it competes with page zoom.zoomOutProgressreports the progress from 0 to 1, so your own controls can follow along.
Drivers
The driver is the engine that animates the transforms. The default is CSS. 'waapi' uses Web Animations; 'gsap', 'anime' and 'motion' use those libraries; and a function is your own. They all follow the same curve, so you can switch without retuning.
transitions: { driver: 'gsap', ease: 'power3.inOut' }
GSAP · Anime.js · Motion · Write your own
That's the whole tour
Every option, method and event is in the API reference. The demo shows what Zumly looks like in bigger interfaces.