14 Şubat 2015 Cumartesi

Animated div in JavaScript

HTML
<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
    </head>
    <body>
        <div id="container">
           
            <div id="box"> </div>
           
            <button onclick="go()" id = "newB">Start!</button>
        </div>
    </body>
</html>

JAVASCRIPT
function go(){
    var pos = 0;
    var box = document.getElementById("box");
    var time = setInterval(go, 10);
   
    function go(){
        if(pos < 150){
            pos += 1;
            box.style.left = pos + "px";
           
            if(pos == 150){
                alert("Done!");
            }
        }
    }
}


Hiç yorum yok:

Yorum Gönder