<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 20.7.1.基本概念和語法 動畫效果其實可以看著過渡效果的升華版: 過渡效果是實現元素在某個(或某些)屬性的兩個不同值之間的狀態變化效果; 動畫效果是預先定義好某個(或某些)屬性的多個不同值之間的狀態變化效果,并對之命名,而后可多次應用在不同的元素上。 簡單說就是: 過渡效果是“實現某元素的某種狀態變化效果”, 動畫效果是“定義某種狀態變化效果,并可拿來用”。 動畫效果的基本語法如下: ``` <style> @keyframes 動畫名{ 0% {屬性設置。。。} /*表示動畫的起始處/* ...... {屬性設置。。。} /*這表示還可以設置中間的若干狀態*/ 100% {屬性設置。。。} /*表示動畫的結束處/* } 選擇器{ animation:動畫名 動畫播放設置; /*動畫播放設置有若干項控制項*/ } </style> ``` 說明: 1,可以設置(定義)若干個動畫(取不同名稱),后續都可以用在不同的元素上(選擇器所決定); 2,每個動畫可以定義若干個關鍵狀態(百分比決定),通常至少需要0%和100%; 3,每個狀態可以定義若干個屬性值,表示動畫播放到該時刻時的元素外觀表現; 4,屬性的設置跟通常css的屬性設置一樣,比如:color:red; width:200px; transform:rotate(90deg); 5,動畫播放設置中可以設置若干項,比如:持續時間,播放方式,延遲時間,是否循環,等等; ## 20.7.2.主要屬性 * animation-name:動畫名; * animation-duration:動畫持續時間; * animation-timing-function:動畫播放播放方式(效果),也有如下幾個常用的效果名: linear:線性過渡,就是勻速進行 ease:平滑過渡,這是默認值 ease-in:由慢到快。 ease-out:由快到慢。 ease-in-out:由慢到快再到慢。 * animation-delay:動畫播放前的延遲時間; * animation-iteration-count:動畫播放循環次數,使用數字或infinite(無限); * animation-direction:動畫播放方向(正向還是反向),可用的值有: normal:常規(就是從前往后播放) reverse:反向(就是從后往前播放) alternate:交替(就是先從前往后,再從后往前),播放次數大于1次才有意義 alternate-reverse:反向交替(就是先從后往前,再從前往后),播放次數大于1次才有意義 * animation-fill-mode:動畫停止(播放結束)時元素停留的狀態,可用的值有: forwards: 停留在前面(動畫播放的結尾處); backwards: 停留在后面(動畫播放的開時處); both: 兩邊都可停(動畫停在哪邊就哪邊); * animation-play-state:設置動畫啟動或暫停,有兩個可用的值: running: 運行狀態(默認值),也就是運行動畫效果; paused: 暫停狀態,也就是動畫效果運行中停下來(此時如果需要還可以繼續運行); * animation:上述屬性的綜合屬性,并依次按該順序列出(不需要的項直接省略); 舉例1: ``` @keyframes ani1{ 0%{ background:red; transform:rotate(0deg);} 100%{ background:blue; transform:rotate(360deg);} } .c1{ animation-name: ani1; animation-duration: 3s; animation-timing-function: ease-in-out; animation-iteration-count:infinite; } ``` 舉例2: ``` (本例跟上面例1的效果一樣,無非是用了綜合屬性animation) $keyframes ani1{ 0%{ background:red; transform:rotate(0deg);} 100%{ background:blue; transform:rotate(360deg);} } .c1{ animation: ani1 3s ease-in-out infinite; } ``` 代碼示例: ![](https://img.kancloud.cn/d3/3f/d33f9a0cecc0df4e55316cc9973b654a_814x508.png) 演示animation-direction,和animation-fill-mode: ``` <style> @keyframes moveLeft2Right{ 0%{ left:0px; } 100%{ left:800px; } } div{ border:solid 1px red; width: 100px; height:50px; margin:5px; position:relative; left:0px; animation-name:moveLeft2Right; animation-timing-function:linear; animation-duration: 5s; animation-iteration-count:3; } .box1{ animation-direction: normal; animation-fill-mode: forwards; } .box1:hover{ animation-play-state:paused; } .box2{ animation-direction: reverse; animation-fill-mode: backwards; } .box3{ animation-direction: alternate; animation-fill-mode: both; } .box4{ animation-direction: alternate-reverse; animation-fill-mode: both; } </style> </head> <body> <div class="box1">normal, forwards</div> <div class="box2">reverse, backwards</div> <div class="box3">alternate, both</div> <div class="box4">alternate-reverse, both</div> </body> ``` ## 20.7.3.案例 ![](https://img.kancloud.cn/e4/6d/e46d825ee991ab43fb2bb7f82b2e7475_728x403.png) ### 連續播放效果的代碼: ``` <style> @keyframes xuanzhuan{ 0%{ transform:rotatex(-15deg) rotatey(0deg); } 100%{ transform:rotatex(-15deg) rotatey(360deg); } } .box{ border:solid 0px red; width:960px; margin:50px auto 10px; perspective: 1200px; perspective-origin: center center; } .box>.container{ border:solid 0px blue; width:200px; height:300px; position: relative; left:50%; margin-left:-100px; transform-style:preserve-3d; transform:rotatex(-15deg); animation-name: xuanzhuan; animation-duration: 6s; animation-timing-function: linear; animation-iteration-count: infinite; } .box>.container:hover{ animation-play-state: paused; } .box>.container>img{ width:200px; height:300px; position: absolute; left:0; top:0; transform-origin: center center; } .box>.container>img:nth-child(1){transform: rotatey(0deg) translatez(300px)} .box>.container>img:nth-child(2){transform: rotatey(40deg) translatez(300px)} .box>.container>img:nth-child(3){transform: rotatey(80deg) translatez(300px)} .box>.container>img:nth-child(4){transform: rotatey(120deg) translatez(300px)} .box>.container>img:nth-child(5){transform: rotatey(160deg) translatez(300px)} .box>.container>img:nth-child(6){transform: rotatey(200deg) translatez(300px)} .box>.container>img:nth-child(7){transform: rotatey(240deg) translatez(300px)} .box>.container>img:nth-child(8){transform: rotatey(280deg) translatez(300px)} .box>.container>img:nth-child(9){transform: rotatey(320deg) translatez(300px)} </style> </head> <body> <div class="box" title="場景,舞臺"> <div class="container" title="容器"> <img src="images/girl1.jpg" alt=""> <img src="images/girl2.jpg" alt=""> <img src="images/girl3.jpg" alt=""> <img src="images/girl4.jpg" alt=""> <img src="images/girl5.jpg" alt=""> <img src="images/girl6.jpg" alt=""> <img src="images/girl7.jpg" alt=""> <img src="images/girl8.jpg" alt=""> <img src="images/girl9.jpg" alt=""> </div> </div> </body> ``` ### 一走一停播放效果的關鍵代碼: ``` @keyframes xuanzhuan{ 0%{transform:rotatex(-15deg) rotatey(0deg);} /*表示從0%時間到2%時間,旋轉從0到40deg,下同*/ 2%{transform:rotatex(-15deg) rotatey(40deg);} /*表示從2%時間到11%時間,旋轉不變,即不旋轉,下同*/ 11%{transform:rotatex(-15deg) rotatey(40deg);} 13%{transform:rotatex(-15deg) rotatey(80deg);} 22%{transform:rotatex(-15deg) rotatey(80deg);} 24%{transform:rotatex(-15deg) rotatey(120deg);} 33%{transform:rotatex(-15deg) rotatey(120deg);} 35%{transform:rotatex(-15deg) rotatey(160deg);} 44%{transform:rotatex(-15deg) rotatey(160deg);} 46%{transform:rotatex(-15deg) rotatey(200deg);} 55%{transform:rotatex(-15deg) rotatey(200deg);} 57%{transform:rotatex(-15deg) rotatey(240deg);} 66%{transform:rotatex(-15deg) rotatey(240deg);} 68%{transform:rotatex(-15deg) rotatey(280deg);} 77%{transform:rotatex(-15deg) rotatey(280deg);} 79%{transform:rotatex(-15deg) rotatey(320deg);} 88%{transform:rotatex(-15deg) rotatey(320deg);} 90%{transform:rotatex(-15deg) rotatey(360deg);} 99%{transform:rotatex(-15deg) rotatey(360deg);} } ``` ### 補充案例1: ``` <style> ul{ margin:0 auto; padding:8px 0 0; height:42px; background: url(images/滑動門bg1.png) repeat-x; } ul>li{ list-style: none; float:left; height:50px; padding:0 10px; } ul>li>a{ line-height: 33px; height:33px; display: inline-block; color:white; padding-left:15px; background: url(images/滑動門bg2.png) left -48px no-repeat; } ul>li>a:hover{ background-position: left top; } ul>li>a>span{ line-height: 33px; display: inline-block; height:33px; padding-right:15px; background: url(images/滑動門bg2.png) right -48px no-repeat; } ul>li>a:hover>span{ background-position: right top; } </style> </head> <body> <ul> <li><a href=""><span>首頁</span></a></li> <li><a href=""><span>&nbsp;&nbsp;三個字</span></a></li> <li><a href=""><span>在線詞典</span></a></li> <li><a href=""><span>五個字標題</span></a></li> </ul> ``` ### 補充案例2(滑動門): ``` <style> .nav{ display:flex; } .nav>a{ display: inline-block; height:35px; padding-left:7px; background: url(images/bg_r1_c1.png) left top no-repeat; } .nav>a:hover{ background-image: url(images/blue_r1_c1.png); } .nav>a>span{ display: inline-block; height:35px; line-height: 35px; padding-right:25px; background: url(images/bg_r1_c2.png) right top no-repeat; } .nav>a:hover>span{ background-image: url(images/blue_r1_c2.png); } </style> </head> <body> <div class="nav"> <a href=""><span>首頁</span></a> <a href=""><span>三個字</span></a> <a href=""><span>四字標題</span></a> <a href=""><span>五個字標題</span></a> </div> ``` ### 補充案例3(手風琴效果): ``` <meta charset="UTF-8"> <title>Document</title> <style> .box{ display: flex; border:solid 1px red; width:600px; margin:0 auto; } .box>div{ /*下一行表示,如果容器盒子放下子盒子的設置寬度還有剩余,就去按該比例“分配” 這里,因為所有div都是1,所以就是均分剩余空隙*/ flex:1; height:240px; width:100px; margin:1px; border:solid 1px blue; transition:flex 1s, background 1s; } .box>div:hover{ flex:1.5; background: yellow; } </style> </head> <body> <div class="box"> <div>內容1內容1內容1內容1內容1內容1內容1內容1內容1內容1內容1內容1內容1內容1內容1內容1內容1</div> <div>內容2內容2內容2內容2內容2內容2內容2內容2內容2內容2</div> <div>內容3內容3內容3內容3內容3內容3內容3內容3內容3內容3內容3內容3內容3內容3內容3內容3內容3內容3內容3內容3內容3</div> <div>內容4內容4內容4內容4內容4內容4</div> <div>內容5內容5內容5內容5內容5內容5內容5內容5內容5內容5內容5內容5內容5內容5內容5內容5內容5內容5內容5內容5內容5內容5</div> </div> </body> ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看