I can't figure out why the cancelAnimationFrame
method does not cancel the requestAnimationFrame
. The console still logs the message. Can anyone provide an explanation?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="Interaktywny poradnik szybkiego startu dla Brackets.">
<link rel="stylesheet" href="test.css">
</head>
<body>
<div class="box1" style="height:100px;width:100px;background:red">
</div>
</body>
<script>
let container;
container = document.getElementsByClassName('box1')[0];
let increase=0
let animate;
function increaseHeight(){
increase = increase + 2;
container.style.height=increase + "px";
if(increase>200){
console.log("cancelAnimation");
cancelAnimationFrame(animate)
}
animate = requestAnimationFrame(increaseHeight);
}
increaseHeight();
</script>
</html>