我在使用javascript

时间:2019-03-17 23:10:35

标签: javascript css

由于某种原因,当我使用JavaScript编辑batata [y]的CSS时,什么也没发生。该代码的目的是创建多个块,然后从顶部移至页面的按钮。

var p1
var p2 = [];
var y = 0;
var x = 0;
var telaJogo, telaJogo2, telaInicio;
var balao = [];
var a = 0;
var batata;

function ola() {
  var bola = setInterval(addBalao, 1000);
}

function addBalao() {
  telaJogo2 = document.getElementById('telaJogo2');
  p2.push(0);
  balao.push(0);
  p1 = Math.floor(Math.random() * 445);
  batata = "balao" + y;
  balao[y] = document.createElement('div'); //create the block
  balao[y].setAttribute("id", batata);
  telaJogo2.appendChild(balao[y]);
  balao[y].style = "top:" + p2[y] + "px;";
  balao[y].style = "left:" + 30 + "px;";
  balao[y].style = "background-color: red;";
  balao[y].style = "height: 50px;";
  balao[y].style = "width: 50px;";
  balao[y].style = "position: absolute";

  console.log("p2[y]" + p2[2]);
  setInterval(ola2, 100);
  y++;
}

function ola2() {
  // move block
  for (x = 0; x < y; x++) {
    p2[x]++;
    atualiza();
  }
  a = 0;
  //console.log(p2);
}

function atualiza() {
  // update the frame
  balao[x].setAttribute("style", "top:" + p2[x] + "px;");
}
#telaJogo2 {
  height: 800px;
  width: 445px;
  background-color: #90ee90;
}
<body onLoad="ola()">
  <script type="text/javascript">
  </script>
  <div id="telaJogo2">
    <div id="barra1"></div>
  </div>

0 个答案:

没有答案