javascript setInterval does not work

2

The following code works like the 'timetout' function (only happening once and not repeating itself), I tried several ways and I could not, if anyone can help me, I already thank you.

    function girar(){           
        var bola = document.getElementById("ball");     
        window.xvel = 10;       
        setInterval(function(){                     
                    window.xvel = parseFloat(window.xvel) + parseFloat("10");                       
        }, 500);            
        bola.style.webkitTransform = "rotate(" + window.xvel + "deg)";      
     }
    
asked by anonymous 09.07.2014 / 02:44

1 answer

4

You need to change the rotation of the callback of setInterval :

function girar(){           
    var bola = document.getElementById("ball");     
    window.xvel = 10;       
    setInterval(function(){                     
        window.xvel = parseFloat(window.xvel) + parseFloat("10");   
        bola.style.webkitTransform = "rotate(" + window.xvel + "deg)"; 
    }, 500);                      
}

Square Ball Example

    
09.07.2014 / 02:48