

offset-keyword Is one of the left, right, top, bottom, or center keyword describing the corresponding offset. Values x-offset Is a or a describing how far from the left edge of the box the origin of the transform is set. The first two values are the same as for the two-value syntax.The other value must be a, a, or one of the keywords top, center, and bottom.One value must be a, a, or one of the keywords left, center, and right.The value must be a, a, or one of the keywords left, center, right, top, and bottom.If two or more values are defined and either no value is a keyword, or the only used keyword is center, then the first value represents the horizontal offset and the second represents the vertical offset. Offsets that are not explicitly defined are reset to their corresponding initial values. The transform-origin property may be specified using one, two, or three values, where each value represents an offset. * y-offset-keyword | x-offset-keyword | z-offset */ * x-offset-keyword | y-offset-keyword | z-offset */ * x-offset-keyword | y-offset | z-offset */

* y-offset-keyword | x-offset-keyword */ * x-offset-keyword | y-offset-keyword */ Transform: translate(-100%, 50%) rotate(45deg) translate(100%, -50%) īy default, the origin of a transform is center. Results in the same transformation as transform-origin: 0 0 This means, this definition transform-origin: -100% 50% This property is applied by first translating the element by the value of the property, then applying the element's transform, then translating by the negated property value. For example, the transformation origin of the rotate() function is the center of rotation. The transformation origin is the point around which a transformation is applied. If you'd like to contribute to the interactive examples project, please clone and send us a pull request. Libraries like Framer Motion take advantage of this fact to build highly-performant animations without stretching or squashing.The source for this interactive example is stored in a GitHub repository. This is an advanced technique, far beyond the scope of this blog post, but know that it's possible to use scale to increase an element's size without distorting its children.
#Transform origin tv
For example, check out this old-timey TV power animation:įor this animation, the squashing effect actually improves the effect!Īnd, if we really don't want our text to squash, we can apply an inverse transform to the child. It may seem like a bummer that scale will stretch/squash the element's contents, but we can actually use this effect to our advantage. This means that the calculations run quicker, leading to smoother motion. With transforms, we can skip a bunch of steps. It's fine to do this once when the page loads, but when we animate something, we need to do all of those calculations many many times a second. Then, the paint algorithms run, figuring out which color every pixel needs to be, and filling it in. If the element has text inside, the line-wrapping algorithm needs to figure out if this new width affects the line breaks.

All of the layout algorithms need to re-run, figuring out exactly where this element and all of its siblings should be.

Think about how much work is required when we change something like width. Incidentally, this is what makes transform such a good choice for animations! All of these transforms essentially treat our element like a flat image, warping and contorting it as you might in Photoshop. This reveals an important truth about transforms: elements are flattened into a texture.
