css3变形——transform
2016-07-28 00:44:05 0 举报
AI智能生成
CSS3中的transform属性可以对元素进行旋转、缩放、平移等变形操作,让网页更加生动有趣。其中,rotate()函数可以实现元素的旋转,通过指定角度来控制旋转方向和程度;scale()函数可以实现元素的缩放,通过指定宽度和高度来控制缩放大小;translate()函数可以实现元素的平移,通过指定距离来控制移动位置。此外,还可以通过设置matrix()函数来实现更加复杂的变形效果。使用transform属性可以让页面更加动态化,提升用户体验。
作者其他创作
大纲/内容
Summary
语法:transform: []* | none
取值:--至少一个 CSS transform functions 被应用
none--指定为 不应用transform
标准语法(Formal syntax):
none |
where
= +
where
= [ || || || || || || || || || || ||
|| || || || || || || || || ]+
where
= matrix( [, ]{5,5} )
= translate( | [, | ]? )
= translateX( | )
= translateY( | )
= scale( [, ]? )
= scaleX( )
= scaleY( )
= rotate( )
= skew( [, ]? )
= skewX( )
= skewY( )
= matrix3d( [, ]{15,15} )
= translate3d( | , | , )
= translateZ( )
= scale3d( , , )
= scaleZ( )
= rotate3d( , , , )
= rotateX( )
= rotateY( )
= rotateZ( )
= perspective( )
transform-function
2D变形
translate()
功能:平移
语法: = translate( | [, | ]? )
写法:transform: translate(tx[, ty]); /* 用向量[tx, ty]完成2D平移。如果ty没有指定,它的值默认为0。 */
单向:X方向平移:transform: translateX(tx); /* 在X轴平移指定距离 */
Y方向平移:transform: translateY(ty); /* 在Y轴平移指定距离 */
示例:transform: translate(50px, 20%); /* X方向偏移50px,Y方向偏移其高度的20% */
scale()
功能:缩放
语法: = scale( [, ]? )
写法:transform: scale(sx[, sy]); /*由[sx, sy]描述指定一个二维缩放操作。如果sy 未指定,默认认为和sx的值相同。*/
单向:X方向缩放:transform: scaleX(sx); /* 使用向量[sx, 1] 完成在X方向上的缩放. */
Y方向缩放:transform: scaleY(sy); /* 使用向量[1, sy] 完成在Y方向上的缩放. */
示例:transform: scale(1.2); /* X方向和Y方向缩放1.2倍 */
transform: scale(1, 1.2); /* X方向缩放1倍,Y方向缩放1.2倍 */
rotate()
功能:旋转
语法: = rotate( )
写法:transform: rotate(angle); /* 从原点(由 transform-origin 属性指定)开始按照顺时针方向旋转元素一个特定的角度。此操作对象的矩阵是 [cos(angle) sin(angle) -sin(angle) cos(angle) 0 0] 。 */
示例:transform: rotate(30deg); /* 顺时针旋转30deg */
skew()
功能:倾斜
语法: = skew( [, ]? )
写法:transform: skew(ax[, ay]); /* 元素在X轴和Y轴方向以指定的角度倾斜。如果ay未提供,在Y轴上没有倾斜。 */
单向:X方向倾斜:transform: skewX(angle); /* 绕X轴以指定的角度倾斜 */
Y方向倾斜:transform: skewY(angle); /* 绕Y轴以指定的角度倾斜 */
示例:transform: skew(30deg); /* Y轴往X轴倾斜30deg */
3D变形
translate3d()
功能:3d平移
语法:transform: translate3d(tx, ty, tz);
单向:translateX()
--The translateX() CSS function moves the element horizontally on the plane. This transformation is characterized by a defining how much it moves horizontally.
--translateX(tx) is a shortcut for translate(tx, 0).
translateY()
--The translateY() CSS function moves the element vertically on the plane. This transformation is characterized by a defining how much it moves vertically.
--translateY(ty) is a shortcut for translate(0, ty).
translateZ()
--The translateZ() CSS function moves the element along the z-axis of the 3D space. This transformation is characterized by a defining how much it moves.
--translateZ(tz) is a shorthand for translate3d(0, 0, tz).
scale3d()
功能:3d缩放
语法:transform: scale3d(sx, sy, sz);
单向:scaleX()
--The scaleX() CSS function modifies the abscissa of each element point by a constant factor, except if this scale factor is 1, in which case the function is the identity transform.
The scaling is not isotropic and the angles of the element are not conserved. scaleX(-1) defines an axial symmetry with a vertical axis passing by the origin (as specified by the transform-origin property).
--scaleX(sx) is a shorthand for scale(sx, 1) or for scale3d(sx, 1, 1).
scaleY()
--The scaleY() CSS function modifies the ordinate of each element point by a constant factor except if this scale factor is 1, in which case the function is the identity transform.
The scaling is not isotropic and the angles of the element are not conserved. scaleY(-1) defines an axial symmetry with a horizontal axis passing by the origin (as specified by the transform-origin property).
--scaleY(sy) is a shorthand for scale(1, sy) or for scale3d(1, sy, 1).
scaleZ()
--The scaleZ() CSS function modifies the z-coordinate of each element point by a constant factor, except if this scale factor is 1, in which case the function is the identity transform.
The scaling is not isotropic and the angles of the element are not conserved. scaleZ(-1) defines an axial symmetry along the z-axis passing by the origin (as specified by the transform-origin property).
--scaleZ(sz) is a shorthand for scale3d(1, 1, sz).
rotate3d()
功能:3d旋转
语法:transform: rotate3d(x, y, z, a);
单向:rotateX()
--The rotateX()CSS function defines a transformation that moves the element around the abscissa without deforming it. The amount of movement is defined by the specified angle;
if positive, the movement will be clockwise, if negative, it will be counter-clockwise. The axis of rotation passes by the origin, defined by transform-origin CSS property.
--rotateX(a)is a shorthand for rotate3D(1, 0, 0, a).
rotateY()
--The rotateY()CSS function defines a transformation that moves the element around the ordinate without deforming it. The amount of movement is defined by the specified angle;
if positive, the movement will be clockwise, if negative, it will be counter-clockwise. The axis of rotation passes by the origin, defined by transform-origin CSS property.
--rotateY(a)is a shorthand for rotate3D(0, 1, 0, a).
rotateZ()
--The rotateZ()CSS function defines a transformation that moves the element around the z-axis without deforming it. The amount of movement is defined by the specified angle;
if positive, the movement will be clockwise, if negative, it will be counter-clockwise. The axis of rotation passes by the origin, defined by transform-origin CSS property.
--rotateZ(a)is a shorthand for rotate3D(0, 0, 1, a).
说明:原点与(x, y, z)的连线作为轴旋转a度。
英文定义:
The rotate3d()CSS function defines a transformation that moves the element around a fixed axis without deforming it.
The amount of movement is defined by the specified angle; if positive, the movement will be clockwise, if negative, it will be counter-clockwise.
In the 3D space, rotations have three degrees of liberty, describing an axis of rotation.
The axis of rotation is defined by an [x, y, z] vector and pass by the origin (as defined by the transform-origin CSS property.
If the vector is not normalized, that is the sum of the square of its three coordinates is not 1, it will be normalized internally.
A non-normalizable vector, like the null vector, [0, 0, 0], will cause the rotation not to be applied, without invaliding the whole CSS property.
Properties
transform-origin
功能:transform-origin CSS属性让你更改一个元素变形的原点。
语法:transform-origin: [ | | left | center | right | top | bottom] | [ [ | | left | center | right ] && [ | | top | center | bottom ] ] ?
值:
x-offset
定义变形中心距离盒模型的左侧的或偏移值。
offset-keyword
left,right,top,bottom或center中之一,定义相对应的变形中心偏移。
y-offset
定义变形中心距离盒模型的顶的或偏移值。
x-offset-keyword
left,right或center中之一,定义相对应的变形中心偏移。
y-offset-keyword
top,bottom或center中之一,定义相对应的变形中心偏移。
z-offset
定义变形中心距离用户视线(z=0处)的(不能是)偏移值。
说明:例如,rotate()的transform-origin 是旋转的中心点 (这个属性的应用原理是先用这个属性的负值translate该元素,进行变形,然后再用这个属性的值把元素translate回去)。
示例:
/* 单值语法 */
transform-origin: 2px;
transform-origin: bottom;
/* 双值语法 */
/* 用两个数字值先水平后垂直,用一个数值一关键字或两关键字不强求顺序 */
transform-origin: 3cm 2px; /* x-offset y-offset */
transform-origin: 2px left; /* y-offset x-offset-keyword */
transform-origin: left 2px; /* x-offset-keyword y-offset */
transform-origin: right top; /* x-offset-keyword y-offset-keyword */
transform-origin: top right; /* y-offset-keyword x-offset-keyword */
/* 三值语法 */
transform-origin: 2px 30% 10px; /* x-offset y-offset z-offset */
transform-origin: 2px left 10px; /* y-offset x-offset-keyword z-offset */
transform-origin: left 5px -3px; /* x-offset-keyword y-offset z-offset */
transform-origin: right bottom 2cm; /* x-offset-keyword y-offset-keyword z-offset */
transform-origin: bottom right 2cm; /* y-offset-keyword x-offset-keyword z-offset */
transform-style
功能:transform-style属性指定了,该元素的子元素是(看起来)位于三维空间内,还是在该元素所在的平面内被扁平化。
语法:transform-style: flat | preserve-3d
说明:如果被扁平化,则子元素不会独立的存在于三维空间。
因为该属性不会被(自动)继承,所以必须为元素所有非叶后代节点设置该属性。
perspective
功能:perspective 属性指定了观察者与z=0平面的距离,使具有三维位置变换的元素产生透视效果。z>0的三维元素比正常大,而z<0时则比正常小,大小程度由该属性的值决定。
语法:perspective: none |
值:none:当pespective样式没有被应用时的默认值.
:指定观察者距离z=0平面的距离,为元素及其内容应用透视变换。当值为0或负值时,无透视变换。
说明:三维元素在观察者后面的部分不会绘制出来,即z轴坐标值大于perspective属性值的部分。
默认情况下,消失点位于元素的中心,但是可以通过设置perspective-origin属性来改变其位置。
当该属性值不为0和none时,会创建新的层叠上下文。
perspective-origin
功能:perspective-origin 属性指定了观察者的位置,在属性perspective中被用作消失点。
语法:perspective-origin: [ | | left | center | right | top | bottom] | [ [ | | left | center | right ] && [ | | top | center | bottom ] ]
写法:perspective-origin: x-position /* one-value syntax */
perspective-origin: x-position y-position /* two-value syntax */
当 x-position 和 y-position 为关键字时,以下写法都是允许的:
--perspective-origin: y-position x-position
--perspective-origin: inherit
值:
x-position
指定消失点的横坐标,其值有以下形式:
百分比,相对于元素宽度,可为负值。
长度值,可为负值。
left,关键字,0值的简记。
center,关键字,50%的简记。
right,关键字,100%的简记。
y-position
指定消失点的纵坐标,其值有以下形式:
百分比,相对于元素的高度,可为负值。
长度值,可为负值。
top,关键字,0值得简记。
center,关键字,50%的简记。
bottom,关键字,100%的简记。
backface-visibility
功能:backface-visibility 属性指定当元素背面朝向观察者时是否可见。元素的背面总是透明的,当其朝向观察者时,显示正面的镜像。
语法:backface-visibility: hidden | visible
值:visible 表示背面可见,允许显示正面的镜像。
hidden 表示背面不可见。
0 条评论
下一页