前两个问题的答案可以在规范中找到。
要循环播放: animation-iteration-count: infinite;
将背景颜色循环变化需要指定一个@keyframes
规则。
body { background: #0ff; }
@-webkit-keyframes blink {
0% { background: rgba(255,0,0,0.5); }
50% { background: rgba(255,0,0,0); }
100% { background: rgba(255,0,0,0.5); }
}
@keyframes blink {
0% { background: rgba(255,0,0,0.5); }
50% { background: rgba(255,0,0,0); }
100% { background: rgba(255,0,0,0.5); }
}
#animate {
height: 100px;
width: 100px;
background: rgba(255,0,0,1);
}
#animate {
-webkit-animation-direction: normal;
-webkit-animation-duration: 5s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-name: blink;
-webkit-animation-timing-function: ease;
animation-direction: normal;
animation-duration: 5s;
animation-iteration-count: infinite;
animation-name: blink;
animation-timing-function: ease;
}
(不要忘记使用所有适用的供应商前缀!)
就浏览器支持而言,我无法告诉您具体情况,但无论如何,我建议通过modernizr进行功能检测,并设置JavaScript备用方案。
这里有一个示例在WebKit中起作用并满足您的一些要求。注意:我不使用Mac,因此我不确定您提到的效果具体是什么。