1. 2D transformation
1. transform Set or retrieve the transformation of the object
Value:
none: Specify a 2D transformation in the form of a six-value (a, b, c, d, e, f) transformation matrix, which is equivalent to directly applying a [a, b, c, d, e, f] Transformation matrix
translate(
TranslateX(
translateY(
rotate(
scaleX(
scaleY(
skew(
skewY(
Note: Different browsers require the following prefixes.
Kernel type | Writing |
---|---|
Webkit(Chrome/Safari) | -webkit-transform |
Gecko(Firefox) | -moz-transform |
Presto(Opera) | -o-transform |
Trident(IE) | -ms-transform |
W3C | transform |
Example:
CSS code:
<span style="font-size: 14px;"><span style="color: #800000;"> #transform1 </span>{<span style="color: #ff0000;"> margin</span>:<span style="color: #0000ff;"> 0 auto</span>;<span style="color: #ff0000;"> width</span>:<span style="color: #0000ff;"> 100px</span>;<span style="color: #ff0000;"> height</span>:<span style="color: #0000ff;"> 100px</span>;<span style="color: #ff0000;"> background-color</span>:<span style="color: #0000ff;"> mediumvioletred</span>;<span style="color: #ff0000;"> -webkit-transform</span>:<span style="color: #0000ff;"> rotate(15deg)</span>; }</span>
HTML code:
<span style="font-size: 15px;"><span style="color: #0000ff;"><</span><span style="color: #800000;">div </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="transform1"</span><span style="color: #0000ff;">></span>旋转了15度<span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></span>
2. transform-origin Set or retrieve the object to be transformed at a certain origin.
Value:
left: Specify the abscissa of the origin as leftcenter①: Specify the abscissa of the origin as
centerright: Specify the abscissa of the origin as
Righttop: Specify the ordinate of the origin as
topcenter②: Specify the ordinate of the origin as
centerbottom: Specify the vertical coordinate of the origin as bottom
How to write it in different browsers:
Kernel type | Writing |
---|---|
Webkit(Chrome/Safari) | -webkit-transform-origin |
Gecko(Firefox) | -moz-transform-origin |
Presto(Opera) | -o-transform-origin |
Trident(IE) | -ms-transform-origin |
W3C | transform-origin |
例子:
CSS代码:
<span style="font-size: 15px;"><span style="color: #800000;"> #transform1 </span>{<span style="color: #ff0000;"> margin</span>:<span style="color: #0000ff;"> 0 auto</span>;<span style="color: #ff0000;"> width</span>:<span style="color: #0000ff;"> 100px</span>;<span style="color: #ff0000;"> height</span>:<span style="color: #0000ff;"> 100px</span>;<span style="color: #ff0000;"> background-color</span>:<span style="color: #0000ff;"> mediumvioletred</span>;<span style="color: #ff0000;"> -webkit-transform</span>:<span style="color: #0000ff;"> rotate(15deg)</span>;/*旋转15度*/<span style="color: #ff0000;"> -webkit-transform-origin</span>:<span style="color: #0000ff;"> left top</span>; /*以左上角为原点旋转*/ } </span>
HTML代码:
<span style="font-size: 15px;"><span style="color: #0000ff;"><</span><span style="color: #800000;">div </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="transform1"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></span>
二、过渡样式
1、transition-property 检索或设置对象中的参与过渡的属性。
取值:
<span style="font-size: 15px;"><span style="color: #800000;"> #transform1 </span>{<span style="color: #ff0000;"> margin</span>:<span style="color: #0000ff;"> 0 auto</span>;<span style="color: #ff0000;"> width</span>:<span style="color: #0000ff;"> 100px</span>;<span style="color: #ff0000;"> height</span>:<span style="color: #0000ff;"> 100px</span>;<span style="color: #ff0000;"> background-color</span>:<span style="color: #0000ff;"> red</span>;<span style="color: #ff0000;"> transition-property</span>:<span style="color: #0000ff;"> background-color</span>; }<span style="color: #800000;"> #transform1:hover </span>{<span style="color: #ff0000;"> transition-duration</span>:<span style="color: #0000ff;">.5s</span>;<span style="color: #ff0000;"> transition-timing-function</span>:<span style="color: #0000ff;">ease-in</span>;<span style="color: #ff0000;"> background-color</span>:<span style="color: #0000ff;"> yellow</span>; } </span>
<span style="font-size: 15px;"><span style="color: #0000ff;"><</span><span style="color: #800000;">div </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="transform1"</span><span style="color: #0000ff;">></span>请将鼠标放在上面<span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></span>
<span style="font-size: 15px;"><span style="color: #800000;"> #delay1 </span>{<span style="color: #ff0000;"> background-color</span>:<span style="color: #0000ff;"> antiquewhite</span>;<span style="color: #ff0000;"> width</span>:<span style="color: #0000ff;">100px</span>;<span style="color: #ff0000;"> height</span>:<span style="color: #0000ff;">100px</span>; }<span style="color: #800000;"> #delay1:hover </span>{<span style="color: #ff0000;"> transition-delay</span>:<span style="color: #0000ff;">1s</span>;<span style="color: #ff0000;"> transition-timing-function</span>:<span style="color: #0000ff;">ease-in</span>;<span style="color: #ff0000;"> background-color</span>:<span style="color: #0000ff;"> black</span>; }<span style="color: #800000;"> #delay2 </span>{<span style="color: #ff0000;"> background-color</span>:<span style="color: #0000ff;"> antiquewhite</span>;<span style="color: #ff0000;"> width</span>:<span style="color: #0000ff;">100px</span>;<span style="color: #ff0000;"> height</span>:<span style="color: #0000ff;">100px</span>; }<span style="color: #800000;"> #delay2:hover </span>{<span style="color: #ff0000;"> transition-delay</span>:<span style="color: #0000ff;">4s</span>;<span style="color: #ff0000;"> transition-timing-function</span>:<span style="color: #0000ff;">ease-in</span>;<span style="color: #ff0000;"> background-color</span>:<span style="color: #0000ff;"> blue</span>; } </span>
<span style="font-size: 15px;"><span style="color: #0000ff;"><</span><span style="color: #800000;">div </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="delay1"</span><span style="color: #0000ff;">><span style="color: #000000;">延迟</span></span>1s后开始过渡<span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><</span><span style="color: #800000;">div </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="delay2"</span><span style="color: #0000ff;">></span>延迟4s后开始过渡<span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></span>
<span style="font-size: 15px;"><span style="color: #800000;"> #all </span>{<span style="color: #ff0000;"> width</span>:<span style="color: #0000ff;"> 100px</span>;<span style="color: #ff0000;"> height</span>:<span style="color: #0000ff;"> 100px</span>;<span style="color: #ff0000;"> background-color</span>:<span style="color: #0000ff;"> red</span>; }<span style="color: #800000;"> #all:hover </span>{<span style="color: #ff0000;"> background-color</span>:<span style="color: #0000ff;"> yellow</span>;<span style="color: #ff0000;"> transition-delay</span>:<span style="color: #0000ff;"> .5s</span>;<span style="color: #ff0000;"> transition-timing-function</span>:<span style="color: #0000ff;"> ease-in</span>;<span style="color: #ff0000;"> transform</span>:<span style="color: #0000ff;"> scale(1.5,1.5)</span>;<span style="color: #ff0000;"> transition-duration</span>:<span style="color: #0000ff;"> 1s</span>; } </span>
<span style="font-size: 15px;"><span style="color: #0000ff;"> <</span><span style="color: #800000;">div </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="all"</span><span style="color: #0000ff;">></span>请把鼠标放在上面查看效果<span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></span>