`:
+
+```html
+
+```
+
+The `#digit` div has a fixed width and a border, so it looks like a red window.
+
+We'll make a timer: the digits will appear one by one, in a discrete way.
+
+To achieve that, we'll hide the `#stripe` outside of `#digit` using `overflow: hidden`, and then shift the `#stripe` to the left step-by-step.
There will be 9 steps, a step-move for each digit:
@@ -277,58 +297,60 @@ There will be 9 steps, a step-move for each digit:
}
```
-In action:
-
-[codetabs src="step"]
-
The first argument of `steps(9, start)` is the number of steps. The transform will be split into 9 parts (10% each). The time interval is automatically divided into 9 parts as well, so `transition: 9s` gives us 9 seconds for the whole animation – 1 second per digit.
The second argument is one of two words: `start` or `end`.
-The `start` means that in the beginning of animation we need to do make the first step immediately.
+The `start` means that in the beginning of animation we need to make the first step immediately.
-We can observe that during the animation: when we click on the digit it changes to `1` (the first step) immediately, and then changes in the beginning of the next second.
+In action:
+
+[codetabs src="step"]
+
+A click on the digit changes it to `1` (the first step) immediately, and then changes in the beginning of the next second.
The process is progressing like this:
- `0s` -- `-10%` (first change in the beginning of the 1st second, immediately)
- `1s` -- `-20%`
- ...
-- `8s` -- `-80%`
+- `8s` -- `-90%`
- (the last second shows the final value).
+Here, the first change was immediate because of `start` in the `steps`.
+
The alternative value `end` would mean that the change should be applied not in the beginning, but at the end of each second.
-So the process would go like this:
+So the process for `steps(9, end)` would go like this:
-- `0s` -- `0`
+- `0s` -- `0` (during the first second nothing changes)
- `1s` -- `-10%` (first change at the end of the 1st second)
- `2s` -- `-20%`
- ...
- `9s` -- `-90%`
-Here's `step(9, end)` in action (note the pause between the first digit change):
+Here's `steps(9, end)` in action (note the pause before the first digit change):
[codetabs src="step-end"]
-There are also shorthand values:
+There are also some pre-defined shorthands for `steps(...)`:
- `step-start` -- is the same as `steps(1, start)`. That is, the animation starts immediately and takes 1 step. So it starts and finishes immediately, as if there were no animation.
- `step-end` -- the same as `steps(1, end)`: make the animation in a single step at the end of `transition-duration`.
-These values are rarely used, because that's not really animation, but rather a single-step change.
+These values are rarely used, as they represent not a real animation, but rather a single-step change. We mention them here for completeness.
-## Event transitionend
+## Event: "transitionend"
-When the CSS animation finishes the `transitionend` event triggers.
+When the CSS animation finishes, the `transitionend` event triggers.
It is widely used to do an action after the animation is done. Also we can join animations.
-For instance, the ship in the example below starts to swim there and back on click, each time farther and farther to the right:
+For instance, the ship in the example below starts to sail there and back when clicked, each time farther and farther to the right:
[iframe src="boat" height=300 edit link]
-The animation is initiated by the function `go` that re-runs each time when the transition finishes and flips the direction:
+The animation is initiated by the function `go` that re-runs each time the transition finishes, and flips the direction:
```js
boat.onclick = function() {
@@ -337,11 +359,11 @@ boat.onclick = function() {
function go() {
if (times % 2) {
- // swim to the right
+ // sail to the right
boat.classList.remove('back');
boat.style.marginLeft = 100 * times + 200 + 'px';
} else {
- // swim to the left
+ // sail to the left
boat.classList.add('back');
boat.style.marginLeft = 100 * times - 200 + 'px';
}
@@ -357,7 +379,7 @@ boat.onclick = function() {
};
```
-The event object for `transitionend` has few specific properties:
+The event object for `transitionend` has a few specific properties:
`event.propertyName`
: The property that has finished animating. Can be good if we animate multiple properties simultaneously.
@@ -369,7 +391,7 @@ The event object for `transitionend` has few specific properties:
We can join multiple simple animations together using the `@keyframes` CSS rule.
-It specifies the "name" of the animation and rules: what, when and where to animate. Then using the `animation` property we attach the animation to the element and specify additional parameters for it.
+It specifies the "name" of the animation and rules - what, when and where to animate. Then using the `animation` property, we can attach the animation to the element and specify additional parameters for it.
Here's an example with explanations:
@@ -405,11 +427,92 @@ Here's an example with explanations:
There are many articles about `@keyframes` and a [detailed specification](https://drafts.csswg.org/css-animations/).
-Probably you won't need `@keyframes` often, unless everything is in the constant move on your sites.
+You probably won't need `@keyframes` often, unless everything is in constant motion on your sites.
+
+## Performance
+
+Most CSS properties can be animated, because most of them are numeric values. For instance, `width`, `color`, `font-size` are all numbers. When you animate them, the browser gradually changes these numbers frame by frame, creating a smooth effect.
+
+However, not all animations will look as smooth as you'd like, because different CSS properties cost differently to change.
+
+In more technical details, when there's a style change, the browser goes through 3 steps to render the new look:
+
+1. **Layout**: re-compute the geometry and position of each element, then
+2. **Paint**: re-compute how everything should look like at their places, including background, colors,
+3. **Composite**: render the final results into pixels on screen, apply CSS transforms if they exist.
+
+During a CSS animation, this process repeats every frame. However, CSS properties that never affect geometry or position, such as `color`, may skip the Layout step. If a `color` changes, the browser doesn't calculate any new geometry, it goes to Paint -> Composite. And there are few properties that directly go to Composite. You can find a longer list of CSS properties and which stages they trigger at
.
+
+The calculations may take time, especially on pages with many elements and a complex layout. And the delays are actually visible on most devices, leading to "jittery", less fluid animations.
+
+Animations of properties that skip the Layout step are faster. It's even better if Paint is skipped too.
+
+The `transform` property is a great choice, because:
+- CSS transforms affect the target element box as a whole (rotate, flip, stretch, shift it).
+- CSS transforms never affect neighbour elements.
+
+...So browsers apply `transform` "on top" of existing Layout and Paint calculations, in the Composite stage.
+
+In other words, the browser calculates the Layout (sizes, positions), paints it with colors, backgrounds, etc at the Paint stage, and then applies `transform` to element boxes that need it.
+
+Changes (animations) of the `transform` property never trigger Layout and Paint steps. More than that, the browser leverages the graphics accelerator (a special chip on the CPU or graphics card) for CSS transforms, thus making them very efficient.
+
+Luckily, the `transform` property is very powerful. By using `transform` on an element, you could rotate and flip it, stretch and shrink it, move it around, and [much more](https://developer.mozilla.org/docs/Web/CSS/transform#syntax). So instead of `left/margin-left` properties we can use `transform: translateX(…)`, use `transform: scale` for increasing element size, etc.
+
+The `opacity` property also never triggers Layout (also skips Paint in Mozilla Gecko). We can use it for show/hide or fade-in/fade-out effects.
+
+Paring `transform` with `opacity` can usually solve most of our needs, providing fluid, good-looking animations.
+
+For example, here clicking on the `#boat` element adds the class with `transform: translateX(300)` and `opacity: 0`, thus making it move `300px` to the right and disappear:
+
+```html run height=260 autorun no-beautify
+
+
+
+
+```
+
+Here's a more complex example, with `@keyframes`:
+
+```html run height=80 autorun no-beautify
+click me to start / stop
+
+```
## Summary
-CSS animations allow to smoothly (or not) animate changes of one or multiple CSS properties.
+CSS animations allow smoothly (or step-by-step) animated changes of one or multiple CSS properties.
They are good for most animation tasks. We're also able to use JavaScript for animations, the next chapter is devoted to that.
@@ -419,9 +522,11 @@ Limitations of CSS animations compared to JavaScript animations:
+ Simple things done simply.
+ Fast and lightweight for CPU.
- JavaScript animations are flexible. They can implement any animation logic, like an "explosion" of an element.
-- Not just property changes. We can create new elements in JavaScript for purposes of animation.
+- Not just property changes. We can create new elements in JavaScript as part of the animation.
```
-The majority of animations can be implemented using CSS as described in this chapter. And `transitionend` event allows to run JavaScript after the animation, so it integrates fine with the code.
+In early examples in this chapter, we animate `font-size`, `left`, `width`, `height`, etc. In real life projects, we should use `transform: scale()` and `transform: translate()` for better performance.
+
+The majority of animations can be implemented using CSS as described in this chapter. And the `transitionend` event allows JavaScript to be run after the animation, so it integrates fine with the code.
But in the next chapter we'll do some JavaScript animations to cover more complex cases.
diff --git a/7-animation/2-css-animations/bezier-linear.svg b/7-animation/2-css-animations/bezier-linear.svg
index 34949d61..0c2e970f 100644
--- a/7-animation/2-css-animations/bezier-linear.svg
+++ b/7-animation/2-css-animations/bezier-linear.svg
@@ -1 +1 @@
-1 2
\ No newline at end of file
+1 2
\ No newline at end of file
diff --git a/7-animation/2-css-animations/bezier-train-over.svg b/7-animation/2-css-animations/bezier-train-over.svg
index ff5501c4..d12d0922 100644
--- a/7-animation/2-css-animations/bezier-train-over.svg
+++ b/7-animation/2-css-animations/bezier-train-over.svg
@@ -1 +1 @@
-(1,1) (0,0) (0,1) (1,0) 1 2 4 3
\ No newline at end of file
+(1,1) (0,0) (0,1) (1,0) 1 2 4 3
\ No newline at end of file
diff --git a/7-animation/2-css-animations/ease-in-out.svg b/7-animation/2-css-animations/ease-in-out.svg
index 29ef69a1..d5c8809d 100644
--- a/7-animation/2-css-animations/ease-in-out.svg
+++ b/7-animation/2-css-animations/ease-in-out.svg
@@ -1 +1 @@
-1 2 3 4
\ No newline at end of file
+1 2 3 4
\ No newline at end of file
diff --git a/7-animation/2-css-animations/ease-in.svg b/7-animation/2-css-animations/ease-in.svg
index 0e8b797a..38c98ecb 100644
--- a/7-animation/2-css-animations/ease-in.svg
+++ b/7-animation/2-css-animations/ease-in.svg
@@ -1 +1 @@
-1 2 3 4
\ No newline at end of file
+1 2 3 4
\ No newline at end of file
diff --git a/7-animation/2-css-animations/ease-out.svg b/7-animation/2-css-animations/ease-out.svg
index c2837287..9d22eeaf 100644
--- a/7-animation/2-css-animations/ease-out.svg
+++ b/7-animation/2-css-animations/ease-out.svg
@@ -1 +1 @@
-1 2 3 4
\ No newline at end of file
+1 2 3 4
\ No newline at end of file
diff --git a/7-animation/2-css-animations/ease.svg b/7-animation/2-css-animations/ease.svg
index a3a1feec..8f9d41fe 100644
--- a/7-animation/2-css-animations/ease.svg
+++ b/7-animation/2-css-animations/ease.svg
@@ -1 +1 @@
-1 2 3 4
\ No newline at end of file
+1 2 3 4
\ No newline at end of file
diff --git a/7-animation/2-css-animations/train-curve.svg b/7-animation/2-css-animations/train-curve.svg
index f1523599..298dacd4 100644
--- a/7-animation/2-css-animations/train-curve.svg
+++ b/7-animation/2-css-animations/train-curve.svg
@@ -1 +1 @@
-1 2 4 3
\ No newline at end of file
+1 2 4 3
\ No newline at end of file
diff --git a/7-animation/3-js-animation/1-animate-ball/solution.md b/7-animation/3-js-animation/1-animate-ball/solution.md
index 5d3f08ee..0dc67b8b 100644
--- a/7-animation/3-js-animation/1-animate-ball/solution.md
+++ b/7-animation/3-js-animation/1-animate-ball/solution.md
@@ -2,7 +2,7 @@ To bounce we can use CSS property `top` and `position:absolute` for the ball ins
The bottom coordinate of the field is `field.clientHeight`. The CSS `top` property refers to the upper edge of the ball. So it should go from `0` till `field.clientHeight - ball.clientHeight`, that's the final lowest position of the upper edge of the ball.
-To to get the "bouncing" effect we can use the timing function `bounce` in `easeOut` mode.
+To get the "bouncing" effect we can use the timing function `bounce` in `easeOut` mode.
Here's the final code for the animation:
diff --git a/7-animation/3-js-animation/1-animate-ball/solution.view/index.html b/7-animation/3-js-animation/1-animate-ball/solution.view/index.html
index 7e031e8d..146033cf 100644
--- a/7-animation/3-js-animation/1-animate-ball/solution.view/index.html
+++ b/7-animation/3-js-animation/1-animate-ball/solution.view/index.html
@@ -21,7 +21,7 @@
}
function bounce(timeFraction) {
- for (let a = 0, b = 1, result; 1; a += b, b /= 2) {
+ for (let a = 0, b = 1; 1; a += b, b /= 2) {
if (timeFraction >= (7 - 4 * a) / 11) {
return -Math.pow((11 - 6 * a - 11 * timeFraction) / 4, 2) + Math.pow(b, 2)
}
diff --git a/7-animation/3-js-animation/2-animate-ball-hops/solution.view/index.html b/7-animation/3-js-animation/2-animate-ball-hops/solution.view/index.html
index b246f422..f587ff60 100644
--- a/7-animation/3-js-animation/2-animate-ball-hops/solution.view/index.html
+++ b/7-animation/3-js-animation/2-animate-ball-hops/solution.view/index.html
@@ -21,7 +21,7 @@
}
function bounce(timeFraction) {
- for (let a = 0, b = 1, result; 1; a += b, b /= 2) {
+ for (let a = 0, b = 1; 1; a += b, b /= 2) {
if (timeFraction >= (7 - 4 * a) / 11) {
return -Math.pow((11 - 6 * a - 11 * timeFraction) / 4, 2) + Math.pow(b, 2)
}
diff --git a/7-animation/3-js-animation/article.md b/7-animation/3-js-animation/article.md
index 00495434..be648314 100644
--- a/7-animation/3-js-animation/article.md
+++ b/7-animation/3-js-animation/article.md
@@ -77,7 +77,7 @@ setInterval(animate3, 20);
These several independent redraws should be grouped together, to make the redraw easier for the browser and hence load less CPU load and look smoother.
-There's one more thing to keep in mind. Sometimes when CPU is overloaded, or there are other reasons to redraw less often (like when the browser tab is hidden), so we really shouldn't run it every `20ms`.
+There's one more thing to keep in mind. Sometimes CPU is overloaded, or there are other reasons to redraw less often (like when the browser tab is hidden), so we really shouldn't run it every `20ms`.
But how do we know about that in JavaScript? There's a specification [Animation timing](http://www.w3.org/TR/animation-timing/) that provides the function `requestAnimationFrame`. It addresses all these issues and even more.
@@ -96,7 +96,7 @@ The returned value `requestId` can be used to cancel the call:
cancelAnimationFrame(requestId);
```
-The `callback` gets one argument -- the time passed from the beginning of the page load in microseconds. This time can also be obtained by calling [performance.now()](mdn:api/Performance/now).
+The `callback` gets one argument -- the time passed from the beginning of the page load in milliseconds. This time can also be obtained by calling [performance.now()](mdn:api/Performance/now).
Usually `callback` runs very soon, unless the CPU is overloaded or the laptop battery is almost discharged, or there's another reason.
@@ -159,7 +159,7 @@ Function `animate` accepts 3 parameters that essentially describes the animation
}
```
- It's graph:
+ Its graph:

That's just like `transition-timing-function: linear`. There are more interesting variants shown below.
@@ -227,7 +227,7 @@ See in action (click to activate):
[iframe height=40 src="quad" link]
-...Or the cubic curve or event greater `n`. Increasing the power makes it speed up faster.
+...Or the cubic curve or even greater `n`. Increasing the power makes it speed up faster.
Here's the graph for `progress` in the power `5`:
@@ -283,7 +283,7 @@ The `bounce` function does the same, but in the reverse order: "bouncing" starts
```js
function bounce(timeFraction) {
- for (let a = 0, b = 1, result; 1; a += b, b /= 2) {
+ for (let a = 0, b = 1; 1; a += b, b /= 2) {
if (timeFraction >= (7 - 4 * a) / 11) {
return -Math.pow((11 - 6 * a - 11 * timeFraction) / 4, 2) + Math.pow(b, 2)
}
@@ -397,7 +397,7 @@ The effect is clearly seen if we compare the graphs of `easeIn`, `easeOut` and `

-- Red is the regular variantof `circ` (`easeIn`).
+- Red is the regular variant of `circ` (`easeIn`).
- Green -- `easeOut`.
- Blue -- `easeInOut`.
@@ -405,7 +405,7 @@ As we can see, the graph of the first half of the animation is the scaled down `
## More interesting "draw"
-Instead of moving the element we can do something else. All we need is to write the write the proper `draw`.
+Instead of moving the element we can do something else. All we need is to write the proper `draw`.
Here's the animated "bouncing" text typing:
diff --git a/7-animation/3-js-animation/back.svg b/7-animation/3-js-animation/back.svg
index 836a72cc..fcef09ad 100644
--- a/7-animation/3-js-animation/back.svg
+++ b/7-animation/3-js-animation/back.svg
@@ -1 +1 @@
-0 1 1
\ No newline at end of file
+0 1 1
\ No newline at end of file
diff --git a/7-animation/3-js-animation/bezier-linear.svg b/7-animation/3-js-animation/bezier-linear.svg
index 34949d61..0c2e970f 100644
--- a/7-animation/3-js-animation/bezier-linear.svg
+++ b/7-animation/3-js-animation/bezier-linear.svg
@@ -1 +1 @@
-1 2
\ No newline at end of file
+1 2
\ No newline at end of file
diff --git a/7-animation/3-js-animation/bounce-easeinout.view/index.html b/7-animation/3-js-animation/bounce-easeinout.view/index.html
index 837c50db..aed3d9d0 100644
--- a/7-animation/3-js-animation/bounce-easeinout.view/index.html
+++ b/7-animation/3-js-animation/bounce-easeinout.view/index.html
@@ -26,7 +26,7 @@
function bounce(timeFraction) {
- for (let a = 0, b = 1, result; 1; a += b, b /= 2) {
+ for (let a = 0, b = 1; 1; a += b, b /= 2) {
if (timeFraction >= (7 - 4 * a) / 11) {
return -Math.pow((11 - 6 * a - 11 * timeFraction) / 4, 2) + Math.pow(b, 2)
}
diff --git a/7-animation/3-js-animation/bounce-easeout.view/index.html b/7-animation/3-js-animation/bounce-easeout.view/index.html
index e52eae8d..69dbb7ce 100644
--- a/7-animation/3-js-animation/bounce-easeout.view/index.html
+++ b/7-animation/3-js-animation/bounce-easeout.view/index.html
@@ -22,7 +22,7 @@
}
function bounce(timeFraction) {
- for (let a = 0, b = 1, result; 1; a += b, b /= 2) {
+ for (let a = 0, b = 1; 1; a += b, b /= 2) {
if (timeFraction >= (7 - 4 * a) / 11) {
return -Math.pow((11 - 6 * a - 11 * timeFraction) / 4, 2) + Math.pow(b, 2)
}
diff --git a/7-animation/3-js-animation/bounce-inout.svg b/7-animation/3-js-animation/bounce-inout.svg
index 7274d715..363633ab 100644
--- a/7-animation/3-js-animation/bounce-inout.svg
+++ b/7-animation/3-js-animation/bounce-inout.svg
@@ -1 +1 @@
-0 1 1
\ No newline at end of file
+0 1 1
\ No newline at end of file
diff --git a/7-animation/3-js-animation/bounce.view/index.html b/7-animation/3-js-animation/bounce.view/index.html
index 1be2580d..3575ed82 100644
--- a/7-animation/3-js-animation/bounce.view/index.html
+++ b/7-animation/3-js-animation/bounce.view/index.html
@@ -19,7 +19,7 @@
animate({
duration: 3000,
timing: function bounce(timeFraction) {
- for (let a = 0, b = 1, result; 1; a += b, b /= 2) {
+ for (let a = 0, b = 1; 1; a += b, b /= 2) {
if (timeFraction >= (7 - 4 * a) / 11) {
return -Math.pow((11 - 6 * a - 11 * timeFraction) / 4, 2) + Math.pow(b, 2)
}
diff --git a/7-animation/3-js-animation/circ-ease.svg b/7-animation/3-js-animation/circ-ease.svg
index cf2ed8d9..a7db9abc 100644
--- a/7-animation/3-js-animation/circ-ease.svg
+++ b/7-animation/3-js-animation/circ-ease.svg
@@ -1 +1 @@
-0 1 1
\ No newline at end of file
+0 1 1
\ No newline at end of file
diff --git a/7-animation/3-js-animation/circ.svg b/7-animation/3-js-animation/circ.svg
index 1c2beade..3595dd62 100644
--- a/7-animation/3-js-animation/circ.svg
+++ b/7-animation/3-js-animation/circ.svg
@@ -1 +1 @@
-0 1 1
\ No newline at end of file
+0 1 1
\ No newline at end of file
diff --git a/7-animation/3-js-animation/elastic.svg b/7-animation/3-js-animation/elastic.svg
index 851da406..17f04ccd 100644
--- a/7-animation/3-js-animation/elastic.svg
+++ b/7-animation/3-js-animation/elastic.svg
@@ -1 +1 @@
-0 1 1
\ No newline at end of file
+0 1 1
\ No newline at end of file
diff --git a/7-animation/3-js-animation/linear.svg b/7-animation/3-js-animation/linear.svg
index 7a5bd71a..daa753f0 100644
--- a/7-animation/3-js-animation/linear.svg
+++ b/7-animation/3-js-animation/linear.svg
@@ -1 +1 @@
-0 1 1
\ No newline at end of file
+0 1 1
\ No newline at end of file
diff --git a/7-animation/3-js-animation/quad.svg b/7-animation/3-js-animation/quad.svg
index e9bc6ac9..25a4d000 100644
--- a/7-animation/3-js-animation/quad.svg
+++ b/7-animation/3-js-animation/quad.svg
@@ -1 +1 @@
-0 1 1
\ No newline at end of file
+0 1 1
\ No newline at end of file
diff --git a/7-animation/3-js-animation/quint.svg b/7-animation/3-js-animation/quint.svg
index ad8ece28..c879ef93 100644
--- a/7-animation/3-js-animation/quint.svg
+++ b/7-animation/3-js-animation/quint.svg
@@ -1 +1 @@
-0 1 1
\ No newline at end of file
+0 1 1
\ No newline at end of file
diff --git a/7-animation/3-js-animation/text.view/index.html b/7-animation/3-js-animation/text.view/index.html
index e404fe5c..4947e4cd 100644
--- a/7-animation/3-js-animation/text.view/index.html
+++ b/7-animation/3-js-animation/text.view/index.html
@@ -29,14 +29,14 @@ And stood awhile in thought.
timing: bounce,
draw: function(progress) {
let result = (to - from) * progress + from;
- textArea.value = text.substr(0, Math.ceil(result))
+ textArea.value = text.slice(0, Math.ceil(result))
}
});
}
function bounce(timeFraction) {
- for (let a = 0, b = 1, result; 1; a += b, b /= 2) {
+ for (let a = 0, b = 1; 1; a += b, b /= 2) {
if (timeFraction >= (7 - 4 * a) / 11) {
return -Math.pow((11 - 6 * a - 11 * timeFraction) / 4, 2) + Math.pow(b, 2)
}
diff --git a/8-web-components/1-webcomponents-intro/article.md b/8-web-components/1-webcomponents-intro/article.md
index 3279cb13..c3522dea 100644
--- a/8-web-components/1-webcomponents-intro/article.md
+++ b/8-web-components/1-webcomponents-intro/article.md
@@ -26,9 +26,9 @@ The International Space Station:
...And this thing flies, keeps humans alive in space!
-How such complex devices are created?
+How are such complex devices created?
-Which principles we could borrow to make our development same-level reliable and scalable? Or, at least, close to it.
+Which principles could we borrow to make our development same-level reliable and scalable? Or, at least, close to it?
## Component architecture
diff --git a/8-web-components/1-webcomponents-intro/web-components-twitter.svg b/8-web-components/1-webcomponents-intro/web-components-twitter.svg
index 534e629b..8f59f789 100644
--- a/8-web-components/1-webcomponents-intro/web-components-twitter.svg
+++ b/8-web-components/1-webcomponents-intro/web-components-twitter.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/8-web-components/2-custom-elements/article.md b/8-web-components/2-custom-elements/article.md
index 44373191..a84ed119 100644
--- a/8-web-components/2-custom-elements/article.md
+++ b/8-web-components/2-custom-elements/article.md
@@ -115,7 +115,7 @@ customElements.define("time-formatted", TimeFormatted); // (2)
>
```
-1. The class has only one method `connectedCallback()` -- the browser calls it when `` element is added to page (or when HTML parser detects it), and it uses the built-in [Intl.DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat) data formatter, well-supported across the browsers, to show a nicely formatted time.
+1. The class has only one method `connectedCallback()` -- the browser calls it when `` element is added to page (or when HTML parser detects it), and it uses the built-in [Intl.DateTimeFormat](mdn:/JavaScript/Reference/Global_Objects/DateTimeFormat) data formatter, well-supported across the browsers, to show a nicely formatted time.
2. We need to register our new element by `customElements.define(tag, class)`.
3. And then we can use it everywhere.
@@ -149,7 +149,7 @@ The `connectedCallback` triggers when the element is added to the document. Not
In the current implementation of ``, after the element is rendered, further attribute changes don't have any effect. That's strange for an HTML element. Usually, when we change an attribute, like `a.href`, we expect the change to be immediately visible. So let's fix this.
-We can observe attributes by providing their list in `observedAttributes()` static getter. For such attributes, `attributeChangedCallback` is called when they are modified. It doesn't trigger for an attribute for performance reasons.
+We can observe attributes by providing their list in `observedAttributes()` static getter. For such attributes, `attributeChangedCallback` is called when they are modified. It doesn't trigger for other, unlisted attributes (that's for performance reasons).
Here's a new ``, that auto-updates when attributes change:
@@ -320,7 +320,7 @@ For example, buttons are instances of `HTMLButtonElement`, let's build upon it.
class HelloButton extends HTMLButtonElement { /* custom element methods */ }
```
-2. Provide an third argument to `customElements.define`, that specifies the tag:
+2. Provide the third argument to `customElements.define`, that specifies the tag:
```js
customElements.define('hello-button', HelloButton, *!*{extends: 'button'}*/!*);
```
@@ -365,7 +365,7 @@ Our new button extends the built-in one. So it keeps the same styles and standar
## References
- HTML Living Standard: .
-- Compatiblity: .
+- Compatiblity: .
## Summary
@@ -397,4 +397,4 @@ Custom elements can be of two types:
/* */
```
-Custom elements are well-supported among browsers. Edge is a bit behind, but there's a polyfill .
+Custom elements are well-supported among browsers. There's a polyfill .
diff --git a/8-web-components/3-shadow-dom/article.md b/8-web-components/3-shadow-dom/article.md
index fafc4754..92614f77 100644
--- a/8-web-components/3-shadow-dom/article.md
+++ b/8-web-components/3-shadow-dom/article.md
@@ -37,7 +37,7 @@ input::-webkit-slider-runnable-track {
Once again, `pseudo` is a non-standard attribute. Chronologically, browsers first started to experiment with internal DOM structures to implement controls, and then, after time, shadow DOM was standardized to allow us, developers, to do the similar thing.
-Further on, we'll use the modern shadow DOM standard, covered by [DOM spec](https://dom.spec.whatwg.org/#shadow-trees) other related specifications.
+Further on, we'll use the modern shadow DOM standard, covered by [DOM spec](https://dom.spec.whatwg.org/#shadow-trees) and other related specifications.
## Shadow tree
diff --git a/8-web-components/4-template-element/article.md b/8-web-components/4-template-element/article.md
index d0fe12af..5499c4ed 100644
--- a/8-web-components/4-template-element/article.md
+++ b/8-web-components/4-template-element/article.md
@@ -1,7 +1,7 @@
# Template element
-A built-in `` element serves as a storage for HTML markup templates. The browser ignores it contents, only checks for syntax validity, but we can access and use it in JavaScript, to create other elements.
+A built-in `` element serves as a storage for HTML markup templates. The browser ignores its contents, only checks for syntax validity, but we can access and use it in JavaScript, to create other elements.
In theory, we could create any invisible element somewhere in HTML for HTML markup storage purposes. What's special about ``?
diff --git a/8-web-components/5-slots-composition/article.md b/8-web-components/5-slots-composition/article.md
index 78f23fbb..c41e26e0 100644
--- a/8-web-components/5-slots-composition/article.md
+++ b/8-web-components/5-slots-composition/article.md
@@ -103,11 +103,11 @@ The result is called "flattened" DOM:
...But the flattened DOM exists only for rendering and event-handling purposes. It's kind of "virtual". That's how things are shown. But the nodes in the document are actually not moved around!
-That can be easily checked if we run `querySelector`: nodes are still at their places.
+That can be easily checked if we run `querySelectorAll`: nodes are still at their places.
```js
// light DOM nodes are still at the same place, under ``
-alert( document.querySelector('user-card span').length ); // 2
+alert( document.querySelectorAll('user-card span').length ); // 2
```
So, the flattened DOM is derived from shadow DOM by inserting slots. The browser renders it and uses for style inheritance, event propagation (more about that later). But JavaScript still sees the document "as is", before flattening.
@@ -130,6 +130,7 @@ For example, the second `` here is ignored (as it's not a top-level child
If there are multiple elements in light DOM with the same slot name, they are appended into the slot, one after another.
For example, this:
+
```html
John
@@ -227,11 +228,11 @@ The flattened DOM looks like this: