Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS transform to rotate an element in an oval path

I have a jsfiddle here - http://jsfiddle.net/w23v50h5/1/

        div {
            position: absolute;
            left: 315px;
            top: 143px;
            width: 50px;
            height: 50px;
            background: red;

            -webkit-animation: myOrbit 6s linear infinite; 
               -moz-animation: myOrbit 6s linear infinite; 
                 -o-animation: myOrbit 6s linear infinite; 
                    animation: myOrbit 6s linear infinite; 

        }

        @-webkit-keyframes myOrbit {
            from { -webkit-transform: rotate(0deg) translateX(5px) translateY(120px) rotate(0deg);}
            to   { -webkit-transform: rotate(360deg) translateX(5px) translateY(120px) rotate(-360deg); }
        }

        @-moz-keyframes myOrbit {
            from { -moz-transform: rotate(0deg) translateX(100px) rotate(0deg); }
            to   { -moz-transform: rotate(360deg) translateX(100px) rotate(-360deg); }
        }

        @-o-keyframes myOrbit {
            from { -o-transform: rotate(0deg) translateX(100px) rotate(0deg); }
            to   { -o-transform: rotate(360deg) translateX(100px) rotate(-360deg); }
        }

        @keyframes myOrbit {
            from { transform: rotate(0deg) translateX(100px) rotate(0deg); }
            to   { transform: rotate(360deg) translateX(100px) rotate(-360deg); }
        }

I'm using css trasform to move an element in an oval shape.

I'd like the path the element is moving on to be a flatter oval shape.

I also like to scale the element so it's smaller at the top of the oval and larger at the bottom so it gives the impression of oval orbit going backwards and coming forwards.

Can anyone help to make the orbit flatter and scale the element.

like image 540
ttmt Avatar asked Oct 22 '14 21:10

ttmt


People also ask

How do you move an element in a circular path in CSS?

Step 1 : CSS of the Parent ElementGive equal height and width, and make its border-radius as 50% so that it becomes circular in shape. Add the initial value of transform property. Also add transition property for animating the transform property.

How do you rotate an element in CSS?

CSS rotate() You can rotate an element clockwise or counter-clockwise. Let's take a look at the syntax for the rotate() function: transform: rotate(angle); The value “angle” represents the number of degrees the element should rotate.

Can I use CSS transform rotate?

The transform property applies a 2D or 3D transformation to an element. This property allows you to rotate, scale, move, skew, etc., elements.

How do you rotate the z axis in CSS?

rotateZ() The rotateZ() CSS function defines a transformation that rotates an element around the z-axis without deforming it. Its result is a <transform-function> data type.


1 Answers

you can use a % instead "from to" in your animation like this:

 0%  { -webkit-transform: rotate(0deg) translateX(5px) translateY(120px) rotate(0deg) scale(1); }
 25%  { -webkit-transform: rotate(90deg) translateX(5px) translateY(120px) rotate(-90deg) scale(.75); }
 50%  { -webkit-transform: rotate(180deg) translateX(5px) translateY(120px) rotate(-180deg) scale(.60); }
 75%  { -webkit-transform: rotate(270deg) translateX(5px) translateY(120px) rotate(-270deg) scale(.75); }
 100%  { -webkit-transform: rotate(360deg) translateX(5px) translateY(120px) rotate(-360deg) scale(1); }

A jsfiddle implementation: http://jsfiddle.net/jutmLgud/

like image 168
xzegga Avatar answered Oct 25 '22 08:10

xzegga