首页 > 开发 > CSS > 正文

css3强大的动画效果animate使用说明及浏览器兼容介绍

2024-07-11 08:29:05
字体:
来源:转载
供稿:网友
好久没更新blog,上次发文(11月8日)到现在刚好一个月,期间项目上的东西比较多,一时觉得时间比较紧,没来得及更新。这个星期总算是告一段落,补上几篇技术性的文章。好吧,第一篇是关于css3动画的使用。
昨天突然看到jing.fm(这个音乐网站非常不错,很多效果我都很喜欢,如果你有兴趣,可以去围观下)上音乐播放时,专辑的转动效果很不错,所以准备自己动手写下,以备后用。结果第一次使用animate就遇到了坑爹的事情,特吐槽下。
一、最终的效果

如上图所示,最终是想让这个专辑的图片转动起来,模拟出唱片播放的效果(你可以去jing.fm上看看真实的效果,很赞,现在很多音乐网站都添加了这个效果)。
二、结构代码

复制代码
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>音乐专辑播放模拟</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div id="bd">
<div id="musicBox">
<div class="cover rotateCD"></div>
<div class="mask"></div>
</div>
</div>
</body>
</html>

从上面的代码可以看出,由于是使用css3强大的动画效果,所以我的结构定义的非常简单(在符合语义的前提下),同时没有引用到javascript脚本文件。
musicBox来限定外围框的大小,内部的cover用来显示专辑封面图片,这个图片是下图左边图片这样的,四四方方,不是圆形,所以我在后面做了个mask的div,它不做其他事情,只是用来容纳一个遮罩(下图右边图片),盖住图片圆形之外的部分。
    
三、css3样式表

复制代码
代码如下:
@charset utf-8;
/* common: rotateCD */
@-webkit-keyframes myrotate{
0%{
-webkit-transform : rotate(0deg);
}
100%{
-webkit-transform : rotate(360deg);
}
}
@-moz-keyframes myrotate{
0%{
-moz-transform : rotate(0deg);
}
100%{
-moz-transform : rotate(360deg);
}
}
@-ms-keyframes myrotate{
0%{
-ms-transform : rotate(0deg);
}
100%{
-ms-transform : rotate(360deg);
}
}
@-o-keyframes myrotate{
0%{
-o-transform : rotate(0deg);
}
100%{
-o-transform : rotate(360deg);
}
}
@keyframes myrotate{
0%{
transform : rotate(0deg);
}
100%{
transform : rotate(360deg);
}
}
.rotateCD{
-webkit-animation: myrotate 9.5s infinite linear;
-moz-animation: myrotate 9.5s infinite linear;
-ms-animation: myrotate 9.5s infinite linear;
-o-animation: myrotate 9.5s infinite linear;
animation: myrotate 9.5s infinite linear;
-webkit-animation-play-state: running;
-moz-animation-play-state: running;
-ms-animation-play-state: running;
-o-animation-play-state: running;
animation-play-state: running;
}
/* module: bd */
#bd{width: 960px;margin: 200px auto 0;}
/* module: musicBox */
#musicBox{position: relative;width: 430px;height: 430px;margin: 0 auto;overflow: hidden;}
#musicBox .cover{width: 300px;height: 300px;margin: 65px;background: url(../img/music1.jpg) 0 0 no-repeat;}
#musicBox .mask{position: absolute;top: 0;left: 0;width: 100%;height: 100%;background: url(../img/playerMask.png) 0 0 no-repeat;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表