kembali ke pelajaran
Materi ini hanya tersedia dalam bahasa berikut: English, Espa??ol, Fran??ais, Italiano, ?????????, ??????????????, ????????????. Tolong, menerjemahkan ke dalam Indonesia.

Animate the ball bouncing to the right

pentingnya: 5

Make the ball bounce to the right. Like this:

Write the animation code. The distance to the left is 100px.

Take the solution of the previous task Animasikan bola yang memantul as the source.

In the task Animasikan bola yang memantul we had only one property to animate. Now we need one more:

The horizontal coordinate changes by another law: it does not ???bounce???, but gradually increases shifting the ball to the right.

We can write one more animate for it.

As the time function we could use linear, but something like makeEaseOut(quad) looks much better.

The code:

let height = field.clientHeight - ball.clientHeight;
let width = 100;

// animate top (bouncing)
  duration: 2000,
  timing: makeEaseOut(bounce),
  draw: function(progress) { = height * progress + 'px'

// animate left (moving to the right)
  duration: 2000,
  timing: makeEaseOut(quad),
  draw: function(progress) { = width * progress + "px"

Buka solusi di kotak pasir.