CSS3旋轉(zhuǎn)動(dòng)畫(360度旋轉(zhuǎn)、旋轉(zhuǎn)放大、放大、移動(dòng)) 用法和實(shí)例
Internet Explorer 10、Firefox、Opera 支持 transform 屬性。
Internet Explorer 9 支持替代的 -ms-transform 屬性(僅適用于 2D 轉(zhuǎn)換)。
Safari 和 Chrome 支持替代的 -webkit-transform 屬性(3D 和 2D 轉(zhuǎn)換)。
Opera 只支持 2D 轉(zhuǎn)換。
transform 屬性向元素應(yīng)用 2D 或 3D 轉(zhuǎn)換。該屬性允許我們對(duì)元素進(jìn)行旋轉(zhuǎn)、縮放、移動(dòng)或傾斜。
為了更好地理解 transform 屬性,請(qǐng)查看這個(gè)演示。
默認(rèn)值: | none |
---|---|
繼承性: | no |
版本: | CSS3 |
JavaScript 語法: | object.style.transform="rotate(7deg)" |
transform: none|transform-functions;
值 | 描述 | 測(cè)試 |
---|---|---|
none | 定義不進(jìn)行轉(zhuǎn)換。 | 測(cè)試 |
matrix(n,n,n,n,n,n) | 定義 2D 轉(zhuǎn)換,使用六個(gè)值的矩陣。 | 測(cè)試 |
matrix3d(n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n) | 定義 3D 轉(zhuǎn)換,使用 16 個(gè)值的 4x4 矩陣。 | |
translate(x,y) | 定義 2D 轉(zhuǎn)換。 | 測(cè)試 |
translate3d(x,y,z) | 定義 3D 轉(zhuǎn)換。 | |
translateX(x) | 定義轉(zhuǎn)換,只是用 X 軸的值。 | 測(cè)試 |
translateY(y) | 定義轉(zhuǎn)換,只是用 Y 軸的值。 | 測(cè)試 |
translateZ(z) | 定義 3D 轉(zhuǎn)換,只是用 Z 軸的值。 | |
scale(x,y) | 定義 2D 縮放轉(zhuǎn)換。 | 測(cè)試 |
scale3d(x,y,z) | 定義 3D 縮放轉(zhuǎn)換。 | |
scaleX(x) | 通過設(shè)置 X 軸的值來定義縮放轉(zhuǎn)換。 | 測(cè)試 |
scaleY(y) | 通過設(shè)置 Y 軸的值來定義縮放轉(zhuǎn)換。 | 測(cè)試 |
scaleZ(z) | 通過設(shè)置 Z 軸的值來定義 3D 縮放轉(zhuǎn)換。 | |
rotate(angle) | 定義 2D 旋轉(zhuǎn),在參數(shù)中規(guī)定角度。 | 測(cè)試 |
rotate3d(x,y,z,angle) | 定義 3D 旋轉(zhuǎn)。 | |
rotateX(angle) | 定義沿著 X 軸的 3D 旋轉(zhuǎn)。 | 測(cè)試 |
rotateY(angle) | 定義沿著 Y 軸的 3D 旋轉(zhuǎn)。 | 測(cè)試 |
rotateZ(angle) | 定義沿著 Z 軸的 3D 旋轉(zhuǎn)。 | 測(cè)試 |
skew(x-angle,y-angle) | 定義沿著 X 和 Y 軸的 2D 傾斜轉(zhuǎn)換。 | 測(cè)試 |
skewX(angle) | 定義沿著 X 軸的 2D 傾斜轉(zhuǎn)換。 | 測(cè)試 |
skewY(angle) | 定義沿著 Y 軸的 2D 傾斜轉(zhuǎn)換。 | 測(cè)試 |
perspective(n) | 為 3D 轉(zhuǎn)換元素定義透視視圖。 | 測(cè)試 |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title</title> <style type="text/css"> div{ width:120px; height:120px; line-height:120px; margin: 20px; background-color: #5cb85c; float: left; font-size: 12px; text-align: center; color:orangered; } /*效果一:360°旋轉(zhuǎn) 修改rotate(旋轉(zhuǎn)度數(shù))*/ .img1 { transition: All 0.4s ease-in-out; -webkit-transition: All 0.4s ease-in-out; -moz-transition: All 0.4s ease-in-out; -o-transition: All 0.4s ease-in-out; } .img1:hover { transform: rotate(360deg); -webkit-transform: rotate(360deg); -moz-transform: rotate(360deg); -o-transform: rotate(360deg); -ms-transform: rotate(360deg); } /*效果二:放大 修改scale(放大的值)*/ .img2 { transition: All 0.4s ease-in-out; -webkit-transition: All 0.4s ease-in-out; -moz-transition: All 0.4s ease-in-out; -o-transition: All 0.4s ease-in-out; } .img2:hover { transform: scale(1.2); -webkit-transform: scale(1.2); -moz-transform: scale(1.2); -o-transform: scale(1.2); -ms-transform: scale(1.2); } /*效果三:旋轉(zhuǎn)放大 修改rotate(旋轉(zhuǎn)度數(shù)) scale(放大值)*/ .img3 { transition: All 0.4s ease-in-out; -webkit-transition: All 0.4s ease-in-out; -moz-transition: All 0.4s ease-in-out; -o-transition: All 0.4s ease-in-out; } .img3:hover { transform: rotate(360deg) scale(1.2); -webkit-transform: rotate(360deg) scale(1.2); -moz-transform: rotate(360deg) scale(1.2); -o-transform: rotate(360deg) scale(1.2); -ms-transform: rotate(360deg) scale(1.2); } /*效果四:上下左右移動(dòng) 修改translate(x軸,y軸)*/ .img4 { transition: All 0.4s ease-in-out; -webkit-transition: All 0.4s ease-in-out; -moz-transition: All 0.4s ease-in-out; -o-transition: All 0.4s ease-in-out; } .img4:hover { transform: translate(0, -10px); -webkit-transform: translate(0, -10px); -moz-transform: translate(0, -10px); -o-transform: translate(0, -10px); -ms-transform: translate(0, -10px); } </style> </head> <body> <div>效果一:360°旋轉(zhuǎn) </div> <div>效果二:放大</div> <div>效果三:旋轉(zhuǎn)放大</div> <div>效果四:上下左右移動(dòng) </div> </body> </html>
CSS3實(shí)現(xiàn)圖片循環(huán)旋轉(zhuǎn)
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>圖片循環(huán)旋轉(zhuǎn)</title> <style> *{margin: 0; padding: 0;} .ta_c{text-align: center; margin-top: 100px;} @-webkit-keyframes rotation{ from {-webkit-transform: rotate(0deg);} to {-webkit-transform: rotate(360deg);} } .Rotation{ -webkit-transform: rotate(360deg); animation: rotation 3s linear infinite; -moz-animation: rotation 3s linear infinite; -webkit-animation: rotation 3s linear infinite; -o-animation: rotation 3s linear infinite; } .img{border-radius: 250px;} </style> </head> <body> <div class="ta_c"> <img class="Rotation img" src="img/01.png" width="500" height="500"/> </div> </body> </html>
HTML實(shí)現(xiàn)圖片360度循環(huán)旋轉(zhuǎn)
效果圖
//css代碼 .header{ -webkit-animation:rotateImg 1s linear infinite; width: 80px ; height: 80px; border: 1px solid #ccc; vertical-align: middle; } @keyframes rotateImg { 0% {transform : rotate(0deg);} 100% {transform : rotate(360deg);} } @-webkit-keyframes rotateImg { 0%{-webkit-transform : rotate(0deg);} 100%{-webkit-transform : rotate(360deg);} } //html代碼 <img class="header" src="me.png">
如對(duì)本文有疑問,請(qǐng)?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會(huì)為你解答!! 點(diǎn)擊進(jìn)入論壇