標籤:
<head> <meta charset="UTF-8"> <title></title> <style type="text/css"> .box { width: 100px; height: 100px; background: #5CBE3E; animation-name: fromLeftToRight;/* 取個名字 */ animation-duration: 4s; /* //變化所要的時間 */ animation-iteration-count: infinite; /* 要迴圈多小次 */ /* (無數次迴圈) */ } /* 定義動畫 */ /* 用名字要和(取個名字)一樣 */ @keyframes fromLeftToRight { from { /* 從什麼開始 */ margin-left: 0; } to { /* 到什麼結束 */ margin-left: 100px; } } </style> </head> <body> <div class="box"></div> </body>
<head> <meta charset="UTF-8"> <title></title> <style type="text/css"> .box { width: 100px; height: 100px; background: #5CBE3E; margin: 5px; animation-name: fromLeftToRight;/*取個名字 */ animation-duration: 3s;/*多小時間迴圈一次 */ animation-iteration-count: infinite; } /* 要迴圈多小次 */ /*(無限次迴圈) */ .box:hover { animation-play-state: paused; }/* 當滑鼠放在圖片上時圖片不移動 */ .reverse { animation-direction: reverse; } /* 從結束到開始地點 */ .alternate { animation-direction: alternate; } /*從開始到結束再從結束到開始 */ .alternate-reverse { animation-direction: alternate-reverse; }/*從結束到開始再開始到結束 */ @keyframes fromLeftToRight { from {/* 從什麼開始 */ margin-left: 0; } to {/* 到什麼結束 */ margin-left: 300px; } } </style> </head> <body> <div class="box"></div> <div class="box reverse"></div> <div class="box alternate"></div> <div class="box alternate-reverse"></div> </body>
<head> <meta charset="UTF-8"> <title></title> <style type="text/css"> img { opacity: 0; } img:hover { animation: fadeIn 1s ease-in forwards; } /* hover的變化過程1秒 */ @keyframes fadeIn { from {/* 從什麼 */ opacity: 0; } to {/* 到什麼 */ opacity: 1; } } </style> </head> <body> <img src="images/1.jpg" alt="一張圖片 " width="300" /> </body>
css動畫效果之一