Skip to content

Commit 6de2c32

Browse files
committed
[LES-3.3/st-compl] animation-frame-funcs
Working with "requestAnimationFrame/cancelAnimationFrame() func's". Worth noting: - two examples on CodePen. core: B-4 / WL-AL
1 parent d15ce9a commit 6de2c32

File tree

2 files changed

+38
-2
lines changed
  • core-courses/4-web-layout-advanced-level/3-animation-on-js

2 files changed

+38
-2
lines changed

core-courses/4-web-layout-advanced-level/3-animation-on-js/3-2-animation-by-interval-funcs/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
<body>
1818
<div class="block"></div>
19+
1920
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.5.1/gsap.min.js"></script>
2021
<script>
21-
2222
let block = document.querySelector('.block');
2323
let start = Date.now(); // запомнить время начала
2424

@@ -56,7 +56,6 @@
5656

5757
// ex 4
5858
//gsap.fromTo(".block", {opacity: 0}, {opacity: 0.5, duration: 1});
59-
6059
</script>
6160
</body>
6261

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>requestAnimationFrame & cancelAnimationFrame() func's</title>
8+
<style>
9+
.block {
10+
width: 100px;
11+
height: 100px;
12+
background-color: lightslategray;
13+
}
14+
</style>
15+
</head>
16+
17+
<body>
18+
<div class="block"></div>
19+
20+
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.5.1/gsap.min.js"></script>
21+
<script>
22+
let animationId = null;
23+
24+
function test() {
25+
console.count('test');
26+
animationId = requestAnimationFrame(test); // по сути рекурсия.. постоянное обновление/перезапись animationId
27+
}
28+
29+
animationId = requestAnimationFrame(test); // первичный вызов
30+
31+
document.querySelector('.block').addEventListener('click', () => {
32+
cancelAnimationFrame(animationId); // остановка по клику.. согласно animationId
33+
})
34+
</script>
35+
</body>
36+
37+
</html>

0 commit comments

Comments
 (0)