我让 div 在页面上随机移动。
我用“箭头”之类的图片替换了 div,现在我希望它随机移动,并指向正确的方向,(移动时改变旋转角度),而不是总是指向上方。

我想移动时可能会旋转一些角度,但我不知道如何计算旧点和新点之间的角度。
提前致谢!!!

尝试这个
$(document).ready(function(){
    animateIMG();
});
function makeNewPosition(){
    // Get viewport dimensions (remove the dimension of the div)
    var h = $(window).height() - 50;
    var w = $(window).width() - 50;
    var nh = Math.floor(Math.random() * h);
    var nw = Math.floor(Math.random() * w);
    return [nh,nw];    
}
function animateIMG(){
    var newq = makeNewPosition();
    $('img').animate({ top: newq[0], left: newq[1] }, function(){
      animateIMG();        
    });
};