mercredi 1 avril 2015

Does initializing a variable with true or false establish the direction of the content in Javascript?


enter code here
<script>
var switchDirection = false;
function doAnimation() {
var divAdvert = document.getElementById("divAdvert");
var currentLeft = divAdvert.offsetLeft;
var newLocation;
if (!switchDirection) {
newLocation = currentLeft + 2;
if (currentLeft >= 400) {
switchDirection = true;
}
} else {
newLocation = currentLeft - 2;
if (currentLeft <= 0) {
switchDirection = false;
}
}
divAdvert.style.left = newLocation + "px";
}
setInterval(doAnimation, 10);
</script>


I want to know why a new variable with the value of false has been declared in the beginning of the function.


Aucun commentaire:

Enregistrer un commentaire