setInterval() and clearInterval() in Javascript
setInterval() and clearInterval() in Javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Testing Javsript</title>
<style>
#box{
width: 100px;
height : 120px;
background-color: rgb(24, 74, 121);
}
</style>
</head>
<body>
<div id="box">
</div>
<script>
var calc=0;
var b = setInterval(animate,100);
function animate(){
if(calc == 200)
{
clearInterval(b);
}
else{
calc = calc + 10;
var a = document.getElementById("box");
a.style.width = calc + 'px';
}
}
</script>
</body>
</html>
Comments
Post a Comment
I WOULD APPRECIATE IF YOU LEAVE A COMMENT OR YOUR FEEDBACK HERE !!!