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{
      width100px;
      height : 120px;
      background-colorrgb(2474121);  
    }
</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

Popular posts from this blog