Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让图片在页面周围随机移动,并在移动时旋转角度(使用jQuery或CSS)_Jquery_Css_Html_Animation - Fatal编程技术网

如何让图片在页面周围随机移动,并在移动时旋转角度(使用jQuery或CSS)

如何让图片在页面周围随机移动,并在移动时旋转角度(使用jQuery或CSS),jquery,css,html,animation,Jquery,Css,Html,Animation,我让div在页面上随意移动 我用“箭头”之类的图片替换div,现在我希望它随机移动,并指向正确的方向(移动时改变旋转角度),而不是始终指向上 我猜移动时可能会旋转一些角度,但我不知道如何计算新旧点之间的角度 提前感谢 试试这个 $(document).ready(function(){ animateIMG(); }); function makeNewPosition(){ // Get viewport dimensions (remove the dimensio

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

};

使用“速度控制”(speed control)

检查旋转问题:[在此处输入链接描述][1][1]:重新标记手爪,但我希望它随机移动,并指向正确的方向(移动时更改旋转角度),而不是始终指向上。我不知道如何计算新旧点之间的角度。谷歌“矩形到极坐标变换”。