css3不停旋转-基于HTML5+CSS3的图像旋转、无限滚动、文字跳跃特效

本文分享一些基于HTML5+CSS3的动画特效:图片旋转、无限滚动、文字跳跃; 实现起来还是比较容易的,自己尝试一下吧!

1. 图像旋转

疗效图如下:

这个效果看起来并不难实现。 代码清单如下:

<style type="text/css">  
    #liu{  
        width:280px;  
        height: 279px;  
        background: url(shishi.png) no-repeat;  
        border-radius:140px;  
        -webkit-animation:run 6s linear 0s infinite;  
    }  
    #liu:hover{  
        -webkit-animation-play-state:paused;  
    }  
    @-webkit-keyframes run{  
        from{  
            -webkit-transform:rotate(0deg);  
        }  
        to{  
            -webkit-transform:rotate(360deg);  
        }  
    }  
</style>  
<div id="liu"></div>  

1、id为liu的div是用来显示图片的区域,但这里的图片是使用的背景图片,通过设置圆角来达到矩形的效果。

2、代码的关键部分是如何让图片无限旋转。 我们可以使用 -webkit-animation 和 @-webkit-keyframes 的组合来做到这一点。

-webkit-animation是一个复合属性,定义如下:
-webkit-animation: name duration timing-function delay iteration_count direction;
name: 是@-webkit-keyframes 中需要指定的方法,用来执行动画。
duration: 动画一个周期执行的时长。
timing-function: 动画执行的效果,可以是线性的,也可以是"快速进入慢速出来"等。
delay: 动画延时执行的时长。
iteration_count: 动画循环执行次数,如果是infinite,则无限执行。
direction: 动画执行方向。

3、@-webkit-keyframes中的from和to两个属性是指定动画执行的初始值和结束值。

4.-webkit-animation-play-state:暂停; 暂停动画的执行。

2.无限滚动

虽然关于无限滚动的实现css3不停旋转,我们先看一下效果图:

这里我们使用HTML5+CSS3来实现css3不停旋转,比使用JQuery简单很多。 右图是逻辑分析图:

分析完成后,代码就方便编写了。 代码清单如下:

<style type="text/css">  
    *{  
        margin: 0;  
        padding: 0;  
    }  
    #container{  
        width:800px;  
        height:200px;  
        margin:100px auto;  
        overflow: hidden;  
        position: relative;  
    }  
    #container ul{  
        list-style: none;  
        width:4000px;  
        left:0;  
        top:0;  
        position: absolute;  
        -webkit-animation:scoll 6s linear 0s infinite;  
    }  
    #container ul li{  
        float:left;  
        margin-right:20px;  
    }  
    @-webkit-keyframes scoll{  
        from{  
            left:0;  
        }  
        to{  
            left:-1100px;  
        }  
    }   
      
</style>  
<div id="container">  
    <ul>  
        <li><a href="http://www.html5cn.org/home.php?mod=editor&op=blank&charset=utf-8#"><img src="http://www.html5cn.org/images/0.png"></a>  
        </li><li><a href="http://www.html5cn.org/home.php?mod=editor&op=blank&charset=utf-8#"><img src="http://www.html5cn.org/images/1.png"></a>  
        </li><li><a href="http://www.html5cn.org/home.php?mod=editor&op=blank&charset=utf-8#"><img src="http://www.html5cn.org/images/2.png"></a>  
        </li><li><a href="http://www.html5cn.org/home.php?mod=editor&op=blank&charset=utf-8#"><img src="http://www.html5cn.org/images/3.png"></a>  
        </li><li><a href="http://www.html5cn.org/home.php?mod=editor&op=blank&charset=utf-8#"><img src="http://www.html5cn.org/images/4.png"></a>  
        </li><li><a href="http://www.html5cn.org/home.php?mod=editor&op=blank&charset=utf-8#"><img src="http://www.html5cn.org/images/0.png"></a>  
        </li><li><a href="http://www.html5cn.org/home.php?mod=editor&op=blank&charset=utf-8#"><img src="http://www.html5cn.org/images/1.png"></a>  
        </li><li><a href="http://www.html5cn.org/home.php?mod=editor&op=blank&charset=utf-8#"><img src="http://www.html5cn.org/images/2.png"></a>  
        </li><li><a href="http://www.html5cn.org/home.php?mod=editor&op=blank&charset=utf-8#"><img src="http://www.html5cn.org/images/3.png"></a>  
        </li><li><a href="http://www.html5cn.org/home.php?mod=editor&op=blank&charset=utf-8#"><img src="http://www.html5cn.org/images/4.png"></a>  
    </li></ul>  
</div>  

3. 文字跳跃

我们经常可以看到一些用flash完成的文字跳动效果,但现在我们也可以通过HTML5+CSS3轻松实现这样的效果。 效果图如下:

思路分析:

1、因为文本有层次感的跳动,所以要“各有所突破”,每个文本都有自己的“空间”。

2. 每个文本都是先跳后跳,所以我们应该一次增加每个文本的动画持续时间。

根据以上两点的分析,我们仍然可以使用-webkit-animation和@-webkit-keyframes的组合来完成动画的效果。 代码清单如下:

<style type="text/css">  
    h2 span{  
        float:left;  
        position: relative;  
    }  
    h2 span:nth-child(1){  
        -webkit-animation:jump 1s linear 0s infinite alternate;  
    }  
    h2 span:nth-child(2){  
        -webkit-animation:jump 1s linear 0.2s infinite alternate;  
    }  
    h2 span:nth-child(3){  
        -webkit-animation:jump 1s linear 0.4s infinite alternate;  
    }  
    h2 span:nth-child(4){  
        -webkit-animation:jump 1s linear 0.6s infinite alternate;  
    }  
    h2 span:nth-child(5){  
        -webkit-animation:jump 1s linear 0.8s infinite alternate;  
    }  
    @-webkit-keyframes jump  
    {  
        0%{  
            top:0px;  
            color:red;  
        }  
        50%{  
            top:-10px;  
            color:green;  
        }  
        100%{  
            top:10px;  
            color:blue;  
        }  
    }  
</style>  
<h2>  
    <span></span>  
    <span></span>  
    <span></span>  
    <span></span>  
    <span></span>  
</h2>  

需要注意的一点是:span标签默认是内联元素; 对它们进行浮动操作后,它们将成为块级元素。