This commit is contained in:
Ilya Kantor 2017-05-25 11:56:32 +03:00
parent 787d58a83f
commit 455d300d8d
280 changed files with 2 additions and 2 deletions

View file

@ -0,0 +1,17 @@
CSS to animate both `width` and `height`:
```css
/* original class */
#flyjet {
transition: all 3s;
}
/* JS adds .growing */
#flyjet.growing {
width: 400px;
height: 240px;
}
```
Please note that `transitionend` triggers two times -- once for every property. So if we don't perform an additional check then the message would show up 2 times.

View file

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
img {
cursor: pointer;
}
</style>
<style>
#flyjet {
width: 40px;
height: 24px;
transition: all 3s;
}
#flyjet.growing {
width: 400px;
height: 240px;
}
</style>
</head>
<body>
<img id="flyjet" src="https://en.js.cx/clipart/flyjet.jpg">
<script>
flyjet.onclick = function() {
let ended = false;
flyjet.addEventListener('transitionend', function() {
if (!ended) {
ended = true;
alert('Done!');
}
});
flyjet.classList.add('growing');
}
</script>
</body>
</html>

View file

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
img {
cursor: pointer;
}
</style>
<style>
#flyjet {
width: 40px;
/* -> 400px */
height: 24px;
/* -> 240px */
}
</style>
</head>
<body>
<img id="flyjet" src="https://en.js.cx/clipart/flyjet.jpg">
</body>
</html>

View file

@ -0,0 +1,14 @@
importance: 5
---
# Animate a plane (CSS)
Show the animation like on the picture below (click the plane):
[iframe src="solution" height=300]
- The picture grows on click from 40x24px to 400x240px.
- The animation takes 3 seconds.
- At the end output: "Done!".
- During the animation process, there may be more clicks. They shouldn't "break" anything.