以某个角度移动,jquery,animate()?

the*_*ost 2 html javascript css jquery

有没有办法在使用时指定角度

$(this).animate({'left': '+=30px'}, 1000);
Run Code Online (Sandbox Code Playgroud)

我想要

$(this).animate({'48': '+=30px'}, 1000);
Run Code Online (Sandbox Code Playgroud)

48是角度

Yog*_*ogu 11

您可以指定both lefttopproperty:

$(this).animate({left: '+=30px', top: '+=30px'}, 1000);
Run Code Online (Sandbox Code Playgroud)

在这种情况下,角度将是45°.

要指定不同的角度,首先计算cos(α)和sin(α).cosinus指定你必须向右走多远,以及鼻窦走多远,以指定角度形成1个像素的距离.如果要覆盖30像素距离,则将窦和余弦结果乘以30.

  • 以防万一第二段没有意义:http://jsfiddle.net/SMvj3/3/ (5认同)