Home>Article>Web Front-end> Let’s take a look at the transformation and transition effects of boxes using CSS
Let’s take a look at the transformation and transition effects of boxes using CSS
WBOYforward
2022-08-03 15:23:332686browse
This article brings you relevant knowledge aboutcss, which mainly introduces the related issues about transform transformation and transitions transition. Let’s take a look at the transformation and transition effects of CSS boxes. I hope Helpful to everyone.
(1) 1. translate(
[ ,
]): Specify a 2D translation through the vector [tx, ty], tx is the first transition value parameter, and ty is the second transition value parameter option. If is not provided, ty has 0 as its value. That is, translate(x,y), which means that the object is translated according to the set x, y parameter values. When the value is a negative number, the object is moved in the opposite direction. Its base point defaults to the center point of the element, or it can also be based on transform-origin. Make a base point change. For example, transform:translate(100px,20px):
(2) translateX(
): Specify a translation by giving a number in the X direction . Only move the element towards the x-axis. Similarly, its base point is the center point of the element. You can also change the position of the base point according to transform-origin. For example: transform: translate Only move to the Y axis, the base point is at the center point of the element, and the position of the base point can be changed through transform-origin. For example: transform:translateY(20px):
2, scale(x,y) Set the box scaling
scale and scale Moving translate is very similar. It also has three situations: scale(x,y) causes the element to scale horizontally and vertically at the same time (that is, the X-axis and Y-axis scale simultaneously); scaleX(x) only scales the element horizontally ( X-axis scaling); scaleY(y) elements only scale vertically (Y-axis scaling), but they have the same scaling center point and base. The center point is the center position of the element, and the scaling base is 1. If its value is greater than 1 The element will be enlarged, otherwise its value is less than 1, and the element will be reduced. Let’s take a closer look at the specific usage of these three situations:
(1) scale(
[,
]): Provides two methods for performing [sx,sy] scaling vectors The parameter specifies a 2D scale. If the second parameter is not provided, it takes the same value as the first parameter. scale(X,Y) is used to scale the element. You can set the base point of the element through transform-origin. The base point is also at the center of the element. In the base, X represents the horizontal scaling multiple, and Y represents the vertical scaling multiple. , and Y is an optional parameter. If the Y value is not set, it means that the scaling factors in the X and Y directions are the same. And subject to X. For example: transform:scale(2,1.5):
(2) scaleX(
): Use the [sx,1] scaling vector to perform the scaling operation, sx are the required parameters. scaleX means that the element only scales the element along the X-axis (horizontal direction). Its default value is (1,1). Its base point is also at the center of the element. We also change the base point of the element through transform-origin. For example: transform:scaleX(2):
## (3) scaleY(
): Use the [1,sy] scaling vector to perform the scaling operation, sy is the Parameters required. scaleY means that the element only scales the element on the Y axis (vertical direction), and its base point is also at the center of the element. You can change the base point of the element through transform-origin. For example, transform:scaleY(2):
##3, rotate(deg) sets the box rotation
rotate(
): Specify a 2D rotation (2D rotation) on the original element through the specified angle parameter. The transform-origin attribute must first be defined. Transform-origin defines the base point of rotation, where angle refers to the rotation angle. If the set value is a positive number, it means clockwise rotation. If the set value is a negative number, it means counterclockwise rotation. For example: transform:rotate(30deg):
*top left | left top 等价于 0 0 | 0% 0% *top | top center | center top 等价于 50% 0 *III、right top | top right 等价于 100% 0 *left | left center | center left 等价于 0 50% | 0% 50% *center | center center 等价于 50% 50%(默认值) *right | right center | center right 等价于 100% 50% *bottom left | left bottom 等价于 0 100% | 0% 100% *bottom | bottom center | center bottom 等价于 50% 100% *bottom right | right bottom 等价于 100% 100%
其中 left,center right是水平方向取值,对应的百分值为left=0%;center=50%;right=100%而top center bottom是垂直方向的取值,其中top=0%;center=50%;bottom=100%;如果只取一个值,表示垂直方向值不变,我们分别来看看以下几个实例
a { -moz-transition: all 0.5s ease-in; -webkit-transition: all 0.5s ease-in; -o-transition: all 0.5s ease-in; transition: all 0.5s ease-in; }
综合上述我们可以给transition一个速记法:transition:
如下图所示:
相对应的一个示例代码:
p { -webkit-transition: all .5s ease-in-out 1s; -o-transition: all .5s ease-in-out 1s; -moz-transition: all .5s ease-in-out 1s; transition: all .5s ease-in-out 1s; }
The above is the detailed content of Let’s take a look at the transformation and transition effects of boxes using CSS. For more information, please follow other related articles on the PHP Chinese website!