Ahm*_*lfy 11

@keyframes epilepsy {
from {
background: red;
color:blue;
}
to {
background: blue;
color:red;
}
}
.element {
animation-duration: 0.1s;
animation-name: epilepsy;
animation-iteration-count: infinite;
animation-direction: alternate;
}
Run Code Online (Sandbox Code Playgroud)
注意:我没有添加供应商前缀

我有点热心,并使用jQuery和modernizr包括后备.请注意,默认情况下,jQuery animate中不支持background-color转换; jQuery的颜色插件需要
$(document).ready(function() {
// Using Modernizr to test if CSS transition is supported or not
if(!Modernizr.csstransitions){
setInterval(function() {
// Go really crazy and do the amazing voodoo using JavaScript
$('.default').animate({
backgroundColor: 'red',
color: 'blue'
}, 100).animate({
backgroundColor: 'blue',
color: 'red'
}, 100);
}, 100);
});
});
Run Code Online (Sandbox Code Playgroud)
CSS
.divClassRed{
background-color:red;
}
.divClassBlue{
background-color:blue;
}
Run Code Online (Sandbox Code Playgroud)
jQuery的
setInterval(function(){
if($('#myDiv').hasClass('divClassRed')){
$('#myDiv').addClass('divClassBlue').removeClass('divClassRed');
}else{
$('#myDiv').addClass('divClassRed').removeClass('divClassBlue');
}
},1000);
Run Code Online (Sandbox Code Playgroud)