lundi 28 décembre 2015

the if statement do not work in javascript

I want to have a try with the clearInterval() method in some conditions. But it seems do not work anyway.

window.onload = function(){
    var list = document.getElementById("list");

    list.style.position = "relative";

    list.style.left = 0;

    var move = function(){
        list.style.left = parseInt(list.style.left) + 200 + "px";  
        demo[0].innerHTML = parseInt(list.style.left);
    } 

    var myVar = setInterval(move,1000);

    if (parseInt(list.style.left) == 600) {
        clearInterval(myVar); 
    }
}  

I don't konw why there is nothing happened when the value of left property is "600". Thank you very much for help.

Aucun commentaire:

Enregistrer un commentaire