0

我有一个小脚本可以在轨道上移动物体,我想随机化物体的起始位置。

这就是我所说的:http: //jsfiddle.net/W69s6/1018/

HTML

<div class="orbit">
    <div class="circle"></div>
</div>

CSS

.orbit
{
    height: 200px;
    width: 200px;
    background: rgba(0,0,0,0.2);
}

.circle
{
    height: 50px;
    width: 50px;
    background: #00ff00;
    position: absolute;
}

JS

$(document).ready(function() {
    orbit('.circle', 0, 0.01, 100, 75, 75);
});

function orbit(obj, t, ts, r, x, y)
{
    t += ts;

    var top = Math.floor(y - (r * Math.sin(t)));
    var left = Math.floor(x - (r * Math.cos(t)));

    $(obj).animate({
        top: top,
        left: left,
    }, 1, function()
    {
        orbit(obj, t, ts, r, x, y);
    });
}

有没有人擅长数学并且知道如何改变它?

4

1 回答 1

1

更改代码的第一部分:

$(document).ready(function() {
    orbit('.circle', Math.random()*100, 0.01, 100, 75, 75);
});
于 2013-07-24T20:03:35.027 回答