Search code examples
cssgsap

How can I scale and rote an image using Greensock?


I'm working on an image that rotates around a circle. As my image rotates around the circle I would like for it to grow as it rotates. I'm using the example shown in Circular Motion example

TweenMax.to(['#logo'], 10, {bezier:[
  {x:"250px",y:"-40px"},
  {x:"500px",y:"250px"},
  {x:"250px",y:"500px"},
  {x:"0px",y:"250px"},
  {x:"0px",y:"0px"},
],repet:2,ease:Linear.easeNone});
body{
  background-color:#fff;
}
#logo{
  position:absolute;
  left:0;
  top:0;
}

.circle{
  position:relative;
  width:500px;
  height:500px;
  border:1px solid #000;
  border-radius:50%;
  margin:0 auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenMax.min.js"></script>
<div class="circle">
  <img id="logo" src="http://gravatar.com/avatar/5a224f121f96bd037bf6c1c1e2b686fb?s=80">
</div>

My example is below but it doesn't work

    TweenMax.to(['#logo'], 10, {bezier:[
      {x:"250px",y:"-40px", scale:0.2},
      {x:"500px",y:"250px"},
      {x:"250px",y:"500px"},
      {x:"0px",y:"250px", scale:0.8,},
      {x:"0px",y:"0px"},
    ],repet:2,ease:Linear.easeNone});

Solution

  • In order to use the 'bezier' attribute you need to include the morph gsap plugin. https://greensock.com/docs/Plugins/MorphSVGPlugin

    I also found some brackets mistakes and 'repet'. Keep in mind the [] selector for the element is only necessary when you want to animate more than one different element.

    I also think you can't change scale inside the bezier attribute, I also recommend to use the pathDataToBezier in order to get the path, instead of hardcoding it I mean.

    Hope it helps, gsap it's lots of fun.

    TweenMax.to('#logo', 10, {bezier:{
    {x:"250px",y:"-40px"},
    {x:"500px",y:"250px"},
    {x:"250px",y:"500px"},
    {x:"0px",y:"250px"},
    {x:"0px",y:"0px"},
    }, scale: 0.8, repeat:2,ease:Linear.easeNone});