1. 2D-Transformation
1. Transformation Legen Sie die Transformation des Objekts fest oder rufen Sie sie ab
Wert:
Keine: Geben Sie eine 2D-Transformation in Form einer Transformationsmatrix mit sechs Werten (a, b, c, d, e, f) an, was der direkten Anwendung von a [a, b, c, d, e) entspricht , f]Transformationsmatrix
Translate(
translatorY(
Drehen (
scaleX(
ScaleY(
skew(
an
skewY(Hinweis: Verschiedene Browser erfordern die folgenden Präfixe.
Kerneltyp | Schreiben | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Webkit (Chrome/Safari) | -webkit-transform | ||||||||||||
Gecko (Firefox) | -moz-transform | ||||||||||||
Presto (Oper) | -o-transform | ||||||||||||
Trident(IE)
|
-ms-transform | ||||||||||||
W3C | transformieren |
Beispiel:
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 Das zu transformierende Objekt an einem bestimmten Ursprung festlegen oder abrufen.
Wert:
left: Geben Sie die Abszisse des Ursprungs als leftcenter① an: Geben Sie die Abszisse des Ursprungs als
ancenterright: Geben Sie die Abszisse des Ursprungs als
anrechts oben: Geben Sie die Ordinate des Ursprungs als
antopcenter②: Geben Sie die Ordinate des Ursprungs als
ancenterbottom: Geben Sie die Ordinate des Ursprungs als unten an
So schreiben Sie es in verschiedenen Browsern:
Kerneltyp | Schreiben | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Webkit (Chrome/Safari)
|
-webkit-transform-origin | ||||||||||||
Gecko(Firefox) | -moz-transform-origin | ||||||||||||
Presto(Oper) | -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>