Step 6 of 6

Motion and gestures

Tune how a zoom feels, and let a gesture drive the zoom-out as it moves.

Live exampleOpen ↗

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

Gestures

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.