Best way to make an image follow a circular path in JQuery?

后端 未结 2 1701
清酒与你
清酒与你 2021-01-27 06:11

I have an image (red, below), that I want to make travel along a circular path. The red image should always end in the same spot as it started.

Notes:

2条回答
  •  孤独总比滥情好
    2021-01-27 06:58

    Please look into these links:

    • CSS Technique
    • Stackoverflow Answers : Answer 1 || Answer 2
    • JSFiddle : Fiddle 1

       var t = 0;
      
       function moveit() {
         t += 0.05;
      
         var r = 100;
         var xcenter = 100;
         var ycenter = 100;
         var newLeft = Math.floor(xcenter + (r * Math.cos(t)));
         var newTop = Math.floor(ycenter + (r * Math.sin(t)));
         $('#friends').animate({
           top: newTop,
           left: newLeft,
         }, 1, function() {
         moveit();
        });
       }
      
       $(document).ready(function() {
          moveit();
       });
      

提交回复
热议问题