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