源代碼
點擊運行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>教程</title> <style> #myDIV { width: 300px; height: 200px; background: red url('smiley.gif') no-repeat top left/5px 5px; -webkit-animation: mymove 5s infinite; /* Chrome, Safari, Opera */ animation: mymove 5s infinite; } /* Chrome, Safari, Opera */ @-webkit-keyframes mymove { 50% {background: blue bottom right/50px 50px;} } /* Standard syntax */ @keyframes mymove { 50% {background: blue bottom right/50px 50px;} } </style> </head> <body> <p>逐步改變背景屬性:<p> <div id="myDIV"></div> <p>background 屬性是所有背景屬性的簡寫屬性。</p> <p>CSS 中僅有 background-color, background-position, 和 background-size 屬性支持動畫傚果。</p> <p><b>注意:</b>Internet Explorer 9 及更早 IE 版本不支持 CSS 動畫。</p> </body> </html>
運行結果