1. 2D변환
1. 변환 객체 변환 설정 또는 검색
값:
없음: 6개 값(a, b, c, d, e, f) 변환 행렬 형식으로 2D 변환을 지정합니다. 이는 [a, b, c, d, e를 직접 적용하는 것과 같습니다. , f]변환 행렬
번역([, ]). 첫 번째 매개변수는 X축에 해당하고 두 번째 매개변수는 Y축에 해당합니다. 두 번째 매개변수가 제공되지 않으면 기본값은 0입니다.
moveX(translateY(
회전(
scaleX(
ScaleY(
skew(
skewY(
참고: 브라우저마다 다음 접두사가 필요합니다.
内核类型 | 写法 |
---|---|
Webkit(Chrome/Safari) | -webkit-transform |
Gecko(Firefox) | -moz-transform |
Presto(Opera) | -o-transform |
Trident(IE) | -ms-transform |
W3C | transform |
예:
CSS 코드:
<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 코드:
<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. 변환원점 특정 원점에서 변환할 객체를 설정하거나 검색합니다.
값:
<길이>: 길이값으로 좌표값을 지정합니다. 부정적일 수 있습니다.
왼쪽 : 원점 가로좌표를 leftcenter로 지정 ① : 원점 가로좌표를
으로 지정centerright : 원점의 가로좌표를
으로 지정righttop : 원점의 세로좌표를
으로 지정topcenter② : 원점의 세로좌표를
으로 지정centerbottom : 원점의 세로좌표를 하단으로 지정
다양한 브라우저에서 작성하는 방법:
内核类型 | 写法 |
---|---|
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>