Move a <div>

Asked

Viewed 143 times

0

How could I move this DIV using javascript?

function randomization() {
    var randomValue = Math.ceil(Math.random() * 5);
    return randomValue;
  }

function playerMovement(direction) {
  switch (direction) {
    case 1:
      // Andar pra direita
      document.getElementById("player").src = "wlk.jpeg";
      break;
    case 2:
      // Andar pra esquerda
      document.getElementById("player").src = "wlk.jpeg";
      break;
    case 3:
      // Andar pra cima
      document.getElementById("player").src = "wlk.jpeg";
      break;
    case 4:
      // Andar pra baixo
      document.getElementById("player").src = "wlk.jpeg";
      break;
    case 5:
      // Atacar
      document.getElementById("player").src = "atk.png";
      break;
  }
}

function loop() {
  for (i = 0; i < 10; i++) {
    playerMovement(randomization());
  }
}
body {
  background: url("http://htmlcolorcodes.com/assets/images/html-color-codes-color-tutorials-hero-00e10b1f.jpg") no-repeat;
}
<div>
  <img id="player" src="wlk.jpeg" width=100 height=100>
</div>

  • Have a look at the Jquery Animate http://api.jquery.com/animate/

  • Move? Move how? Be more specific in your question.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.