Skip to content

Commit

Permalink
Merge pull request #122 from jhassell/patch-18
Browse files Browse the repository at this point in the history
Update Chapter 18.
  • Loading branch information
bpesquet committed Sep 30, 2017
2 parents 06cd827 + 7d42c63 commit 321d759
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions manuscript/chapter18.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const intervalId = setInterval(callbackFunction, timeBetweenEachCall);

### Stop a repeated action

Let's try to stop the counter once the countdown is complete. We'll also modify the text of the page. Here's the JavaScript code for our example, updated to produce our desired result.
Let's try to stop the counter once the countdown is complete. We'll also modify the text of the page. Here's the JavaScript code for our example, updated to produce our desired result:

```js
// Count down the counter until 0
Expand Down Expand Up @@ -125,7 +125,7 @@ const intervalId = setInterval(decreaseCounter, 1000);

[Click here](https://codepen.io/bpesquet/pen/ybYPbb?editors=1010) to see it in action.

Once the countdown has finished, we call the `setTimeout()` function to set a new page title after a 2 second (2000 milliseconds) delay.
Once the countdown has finished, we call the `setTimeout()` function to set a new page title after a 2 second (2000 millisecond) delay.

The `setTimeout()` function lets you execute a function once after a particular delay, expressed in milliseconds.

Expand All @@ -136,7 +136,7 @@ setTimeout(callbackFunction, timeBeforeCall);

## Animate page elements

The previous solutions were convenient for making our pages a bit more dynamic, but weren't enough for adding real-time animations. Let's look at a better-performing solution.
The previous solutions were convenient for making our pages a bit more dynamic, but weren't enough for adding real-time animation. Let's look at a better-performing solution.

Take, for example, the movement of a `<div>` type element from left to right on the page. We start with the following HTML and CSS code that display a red block on the page.

Expand Down Expand Up @@ -186,11 +186,11 @@ requestAnimationFrame(moveBlock);

[Click here](https://codepen.io/bpesquet/pen/RVWxbW) to see it in action.

After page load, the red block moves (indefinitely) from left to right.
Upon page load, the red block moves (indefinitely) from left to right.

### Start an animation

The example code defines a function called `moveBlock()` which moves the block horizontally to the right. It grabs the current position of the block's left border than adds the value contained in the `movement` variable. Next, it calls the `requestAnimationFrame()` method to keep the animation going.
The example code defines a function called `moveBlock()` which moves the block horizontally to the right. It grabs the current position of the block's left border than adds the value contained in the `movement` variable. Next, the code calls the `requestAnimationFrame()` method to keep the animation going.

Position values are written in pixels. These are the strings you saw that resemble "XXpx," which requires the use of the JavaScript `parseFloat()` function to convert numeric values before making calculations.

Expand Down Expand Up @@ -345,4 +345,4 @@ Write the JavaScript code that makes the ball bounce horizontally.

![Execution result](images/chapter18-04.png)

T> Create a variable with values 1 or -1 to know in which direction the ball should move.
With your solution, create a variable with values 1 or -1 that dictates the direction in which the ball should move.

0 comments on commit 321d759

Please sign in to comment.