案例:动态css3琴弦上的跳动

本案例主要是通过css3的动画技术@keyframes来实现琴弦上的跳动,css3相对于以前版本的css3来说,有很多效果是可以不用js直接用css3就可以实现,今天我们来看看,琴弦上的跳动的实现:案例:动态css3琴弦上的跳动_第1张图片

通过动画可以让下面的音符有规律的运动,还有一个打开的门的效果,都是通过css3来实现的。

代码:

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>琴弦上的跳动</title>

<style type="text/css">

*{margin:0px; padding:0px;}

body{height:680px; overflow:hidden;/*溢出元素强制隐藏*/}

#left,#right{ width:50%; height:680px; position:absolute;/*定位元素*/ top:0px;}

#left{left:0px; background:url(img/2.jpg);background-size:100% 120%; /*延迟2s再发生*/animation:left 3s linear; animation-fill-mode:forwards;/*保持最后1s的状态*/ animation-delay:2s; transform-origin:0px; z-index:99999;}

#right{right:0px; background:url(img/3.jpg); background-size:100% 120%; animation:right 3s linear; animation-fill-mode:forwards; animation-delay:2s;/*保持最后1s的状态*/transform-origin:100%; z-index:99999;}

/*开门咯*/

@keyframes left{

from{ transform:rotateY(0deg)}

to{transform:rotateY(-180deg)}

@keyframes right{

from{ transform:rotateY(0deg)}

to{transform:rotateY(180deg)}

}

/*琴弦跳动*/

#box{width:100%; height:640px; background:url(img/12.jpg) no-repeat; background-size:100% 100%; position:relative;/*参照物*/}

#music{position:absolute; bottom:50px; width:100%; height:230px; background:url(img/bj.png) center repeat-x;}

#music ul{width:1120px; margin:0px auto;}

#music ul li{float:left;  list-style:none;/*去除小黑点*/ height:230px; margin-right:45px; position:relative; animation:music 3s linear infinite;}

#music ul li:nth-child(2){ background:url("img/2.png") no-repeat; width:201px;background-position:bottom;animation-delay:6s;}

#music ul li:nth-child(3){ background:url("img/3.png") no-repeat; width:196px;background-position:bottom;animation-delay:7s;}

#music ul li:nth-child(4){ background:url("img/4.png") no-repeat; width:186px; background-position:bottom;animation-delay:8s;}

#music ul li:nth-child(5){ background:url("img/5.png") no-repeat; width:154px; background-position:bottom;margin-right:0px;animation-delay:9s;}

@keyframes music{

0%{top:0px; background-position:bottom;}

25%{top:50px;background-position:bottom; }

50%{top:0px;background-position:bottom;}

75%{top:50px;background-position:bottom;}

100%{top:0px;background-position:bottom;}

}

/*可爱的猪猪*/

#kan{width:180px; height:180px; position:absolute; background:#fff url(img/1.gif) center no-repeat; top:30px; right:50px; z-index:9999; border-radius:90px;}

#kan:hover{background:#fff url("img/go.png") center no-repeat;}

</style>

</head>


<body>

<div id="left"></div>

    <div id="right"></div>

    <a href="http://www.baidu.com" id="kan">

    </a>

    <div id="box">

    <div id="music">

        <ul>

            <li></li>

                <li></li>

                <li></li>

                <li></li>

                <li></li>

            </ul>

        </div>

    </div>

    

</body>

</html>

有想了解html5和css3的朋友,或者想学前端的朋友都可以来看看。《html5视屏教程》

你可能感兴趣的:(案例:动态css3琴弦上的跳动)