File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed
core-courses/4-web-layout-advanced-level/3-animation-on-js
3-2-animation-by-interval-funcs
3-3-animation-frame-funcs Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change 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
5656
5757 // ex 4
5858 //gsap.fromTo(".block", {opacity: 0}, {opacity: 0.5, duration: 1});
59-
6059 </ script >
6160</ body >
6261
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments