我想创建类似水平单臂土匪游戏的游戏。

我有12个元素并排放置,当我按下按钮时,我希望它们水平移动并停在随机位置。

您能给我一些有关如何实现这一目标的建议吗?

最佳答案

它不是很有效,但是您可以执行以下操作:

var move = setInterval(animation, 50); //50 is only an example value

function animation(){
  $('yourDOMelement').css('transform', 'translateY(1px)'); //maybe -1 depends on direction...
  if(Math.random()*100==2){   //adjust the 100 to your needs
    clearInterval(move);
  }
}


请注意,该代码未经测试,希望您至少能了解我将如何做,然后针对您的问题采用它。

关于javascript - 水平单臂强盗动画,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40702590/

10-12 00:00
查看更多