【问题标题】:How to get a picture to randomly move around a page and rotating angle when moving (using jQuery or CSS)如何让图片在移动时随机移动页面和旋转角度(使用jQuery或CSS)
【发布时间】:2012-10-31 16:27:36
【问题描述】:

我让 div 在页面中随机移动。

old question

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

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

提前致谢!!!

【问题讨论】:

标签: jquery css html animation


【解决方案1】:

试试这个

$(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();        
    });

};

JsFiddle 带速度控制http://jsfiddle.net/D6Svc/

【讨论】:

  • 谢谢,但我希望它随机移动,并指向正确的方向,(移动时改变旋转角度),而不是总是指向上方。我不知道如何计算新旧点之间的角度。
  • 谷歌“矩形到极坐标变换”。
猜你喜欢
  • 2012-05-10
  • 1970-01-01
  • 1970-01-01
  • 2015-06-03
  • 1970-01-01
  • 1970-01-01
  • 2015-03-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多