closes #2248
This commit is contained in:
parent
ec4dcb279a
commit
0585eda755
3 changed files with 0 additions and 0 deletions
|
@ -1,59 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<style>
|
||||
.message-ball {
|
||||
font-size: 20px;
|
||||
line-height: 200px;
|
||||
text-align: center;
|
||||
}
|
||||
.circle {
|
||||
transition-property: width, height, margin-left, margin-top;
|
||||
transition-duration: 2s;
|
||||
position: fixed;
|
||||
transform: translateX(-50%) translateY(-50%);
|
||||
background-color: red;
|
||||
border-radius: 50%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<button onclick="go()">Click me</button>
|
||||
|
||||
<script>
|
||||
|
||||
function go() {
|
||||
showCircle(150, 150, 100, div => {
|
||||
div.classList.add('message-ball');
|
||||
div.append("Hello, world!");
|
||||
});
|
||||
}
|
||||
|
||||
function showCircle(cx, cy, radius, callback) {
|
||||
let div = document.createElement('div');
|
||||
div.style.width = 0;
|
||||
div.style.height = 0;
|
||||
div.style.left = cx + 'px';
|
||||
div.style.top = cy + 'px';
|
||||
div.className = 'circle';
|
||||
document.body.append(div);
|
||||
|
||||
setTimeout(() => {
|
||||
div.style.width = radius * 2 + 'px';
|
||||
div.style.height = radius * 2 + 'px';
|
||||
|
||||
div.addEventListener('transitionend', function handler() {
|
||||
div.removeEventListener('transitionend', handler);
|
||||
callback(div);
|
||||
});
|
||||
}, 0);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,25 +0,0 @@
|
|||
|
||||
# Animated circle with callback
|
||||
|
||||
In the task <info:task/animate-circle> an animated growing circle is shown.
|
||||
|
||||
Now let's say we need not just a circle, but to show a message inside it. The message should appear *after* the animation is complete (the circle is fully grown), otherwise it would look ugly.
|
||||
|
||||
In the solution of the task, the function `showCircle(cx, cy, radius)` draws the circle, but gives no way to track when it's ready.
|
||||
|
||||
Add a callback argument: `showCircle(cx, cy, radius, callback)` to be called when the animation is complete. The `callback` should receive the circle `<div>` as an argument.
|
||||
|
||||
Here's the example:
|
||||
|
||||
```js
|
||||
showCircle(150, 150, 100, div => {
|
||||
div.classList.add('message-ball');
|
||||
div.append("Hello, world!");
|
||||
});
|
||||
```
|
||||
|
||||
Demo:
|
||||
|
||||
[iframe src="solution" height=260]
|
||||
|
||||
Take the solution of the task <info:task/animate-circle> as the base.
|
Loading…
Add table
Add a link
Reference in a new issue