1、html+js:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <link rel="stylesheet" href="./css/reset.css"/>
    <link rel="stylesheet" href="./css/animation.css"/>
    <script type="text/javascript" src="./js/jquery-1.10.2.min.js"></script>
    <title>animation-css3动画</title>
</head>
<body>
<ul class="clear">
    <li><span class="circle"></span><a href="#">Button</a></li>
    <li><span class="circle"></span><a href="#">Elements</a></li>
    <li><span class="circle"></span><a href="#">Forms</a></li>
    <li><span class="circle"></span><a href="#">Charts</a></li>
</ul>
</body>
<script type="text/javascript">
;(function(){
    var items = document.getElementsByTagName('li');
    for(var i = 0; i < items.length; i++){
        items[i].onclick = function(){
//            alert($(this));
            this.getElementsByTagName('span')[0].style.animation = 'circle-opacity 0.5s linear 0s 1';
            this.getElementsByTagName('span')[0].style.webkitAnimation = 'circle-opacity 0.5s linear 0s 1';
            this.getElementsByTagName('span')[0].style.animationFillMode = 'forwards';
            $(this).siblings().children('a').css('color','#333');
            $(this).children('a').css('color',' #2196f3');
            clearAnimation(this);

            //alert(this.getElementsByTagName('span')[0].getAttribute('class'));//弹出circle证明获取到了子元素span
        }
    }
    function clearAnimation(self){
        var sid = window.setInterval(function(){
            self.getElementsByTagName('span')[0].style.animation = '';
            self.getElementsByTagName('span')[0].style.webkitAnimation = '';
            self.getElementsByTagName('span')[0].style.animationFillMode = '';
            sid = window.clearInterval(sid);
        },500);

    }
})(window);
</script>
</html>

 

2、css:

ul{width: 300px;border: red;}
ul li{width: 300px;height: 70px;line-height: 70px;background: #fff;text-align: center;cursor: pointer;overflow: hidden;}
ul li a{font-weight: 900;}
ul li:hover a{
    color: #2196f3!important;
    /*animation: circle-opacity 0.5s linear 0s 1;*/
    /*-webkit-animation-fill-mode:forwards;让动画停在最后是这个属性,*/
    /*animation-fill-mode:forwards;*/
}
ul li a{position: relative;left: -50px;color: #333;top: -30px;}
.circle{background: transparent;border-radius: 50%;width: 70px;height: 70px;display: inline-block;margin: 0 auto;}

@keyframes circle-opacity{
    0% {
        background: rgba(192,225,250,0);
    }
    50% {
        transform:scale(4);
        background: rgba(192,225,250,1);
    }
    100% {
        transform:scale(16);
        background: rgba(192,225,250,0);
    }
}
@-webkit-keyframes circle-opacity{
    0% {
        background: rgba(192,225,250,0);
    }
    50% {
        transform:scale(4);
        background: rgba(192,225,250,1);
    }
    100% {
        transform:scale(16);
        background: rgba(192,225,250,0);
    }
}

posted on 2016-05-11 11:05  杨杨0708  阅读(870)  评论(0编辑  收藏  举报