问题围绕
- 这个随机浮动脚本只允许首先向左然后向顶部进行步进移动,但在完美情况下它会在两者之间
- 它不够光滑
我也尝试过缓动插件
代码在这里:
function ran(min, max)
{
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function moveIt()
{
$(".circle").each(function() {
x = ran(-3, 3);
y = ran(-3, 3);
pos = $(this).position();
nowX = pos.left + x;
nowY = pos.top + y;
$(this).animate({"left": nowX}, {queue:false, duration:400, easing: 'linear'});
$(this).animate({"top": nowY}, {queue:false, duration:400, easing: 'linear'});
});
}
setInterval(moveIt, 400);