【发布时间】:2016-04-24 01:52:55
【问题描述】:
我目前正在使用 Velocity.js 为运动创建一个小游戏。我有一系列动作,我想循环 5 次,但每次启动循环时,我希望行进的距离是随机的。
这是我目前所拥有的,但我知道这些值是在循环运行之前设置的,并且不会在整个过程中改变 - 非常感谢一些帮助,让这些值在每个循环中随机生成。
var $horse = $('#horseGame');
$horse.on('click', '#race', function(){
var $box = $(this).siblings('.box'),
$distance = 10,
$timeTaken = 500;
$distance = Math.floor((Math.random() * 200) + $distance),
$timeTaken = Math.floor((Math.random() * 2000) + $timeTaken);
console.log($distance + " + " + $timeTaken);
var race = [
{
elements: $box,
properties: {
left: $distance
},
options: {
duration: $timeTaken,
loop: 5
}
}
];
$.Velocity.RunSequence(race);
});
谢谢!
【问题讨论】:
标签: javascript loops velocity.js