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