css3 动画
@-webkit-keyframes twinkling{ /*透明度由0到1*/
0%{
opacity:0; /*透明度为0*/
}
100%{
opacity:1; /*透明度为1*/
}
}
Jquery :
$(element).css({"-webkit-animation":"twinkling 1s infinite ease-in-out"}); //在对象element中添加闪烁动画
也可以css3
#element{
-webkit-animation: twinkling 1s infinite ease-in-out;
}
1、ease:(逐渐变慢)默认值,ease函数等同于贝塞尔曲线(0.25, 0.1, 0.25, 1.0);
2、linear:(匀速),linear 函数等同于贝塞尔曲线(0.0, 0.0, 1.0, 1.0);
3、ease-in:(加速),ease-in 函数等同于贝塞尔曲线(0.42, 0, 1.0, 1.0);
4、ease-out:(减速),ease-out 函数等同于贝塞尔曲线(0, 0, 0.58, 1.0);
5、ease-in-out:(加速然后减速),ease-in-out 函数等同于贝塞尔曲线(0.42, 0, 0.58, 1.0);
EG
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<style>
@-webkit-keyframes mymove
{
0% {opacity:0.5;}
20% {opacity:1;margin-left:50px;}
30% {margin-left:200px;-webkit-transform: rotateZ(0deg);}
50%{opacity:0}
60%{opacity:1}
70%{opacity:0;}
75%{opacity:1}
100% {margin-left:0px;-webkit-transform: rotateZ(360deg);}
}
.action{display:block;-webkit-animation: mymove 5s ease-in-out;}
</style>
<div><img id='element' src='1.jpg'></div>
<a onclick="toggleClassTest()">ACTION</a>
<script>
function hasClass(obj, cls) {
return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
}
function addClass(obj, cls) {
if (!this.hasClass(obj, cls)) obj.className += " " + cls;
}
function removeClass(obj, cls) {
if (hasClass(obj, cls)) {
var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
obj.className = obj.className.replace(reg, ' ');
}
}
function toggleClass(obj,cls){
if(hasClass(obj,cls)){
removeClass(obj, cls);
}else{
addClass(obj, cls);
}
}
function toggleClassTest(){
var obj = document. getElementById('element');
toggleClass(obj,"action");
}
</script>
</body>
</html>