基于HTML5+CSS3的图片旋转、无限滚动、文字跳动特效

简介:

本文分享几种基于HTML5+CSS3实现的一些动画特效:图片旋转、无限滚动、文字跳动;实现起来均比较容易,动手来试试!

一、图片旋转

效果图如下:

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

复制代码
<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:paused; 暂停动画的执行。

二、无限滚动

其实关于无限滚动的实现,我们先看看效果图:

我们这里采用HTML5+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>  
复制代码

三、文字跳动

我们经常可以看到用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标签默认是行内元素;但是对他们进行float操作之后,他们会变成块级元素。

sigline.gif
本文转自 K1two2 博客园博客,原文链接:http://www.cnblogs.com/k1two2/p/4992985.html   ,如需转载请自行联系原作者
相关文章
|
16天前
|
前端开发 JavaScript 开发工具
【HTML/CSS】入门导学篇
【HTML/CSS】入门导学篇
23 0
|
1天前
|
前端开发
css_跳动的心制作过程
css_跳动的心制作过程
4 0
|
7天前
|
数据采集 前端开发 网络协议
如何使用代理IP通过HTML和CSS采集数据
如何使用代理IP通过HTML和CSS采集数据
|
11天前
|
前端开发 搜索推荐 数据安全/隐私保护
HTML标签详解 HTML5+CSS3+移动web 前端开发入门笔记(四)
HTML标签详解 HTML5+CSS3+移动web 前端开发入门笔记(四)
18 1
|
11天前
|
PHP
web简易开发——通过php与HTML+css+mysql实现用户的登录,注册
web简易开发——通过php与HTML+css+mysql实现用户的登录,注册
|
18天前
|
JSON JavaScript 前端开发
js是什么、html、css
js是什么、html、css
|
19天前
|
XML 前端开发 JavaScript
css和html
【4月更文挑战第7天】css和html
13 0
|
1月前
|
前端开发 容器 内存技术
使用CSS3画出一个叮当猫HTML源码
本文教程介绍了如何使用CSS3绘制叮当猫,通过HTML结构和CSS样式逐步构建叮当猫的各个部位,如头部、脸部、脖子、身体、手脚等。代码示例展示了如何利用渐变、边框、阴影和定位技巧实现三维效果和细节特征。此外,还添加了眼珠的动画效果,让叮当猫的眼睛能够转动。整个过程适合对CSS3感兴趣的读者参考学习,以提升动态图形创作技能。
16 0
使用CSS3画出一个叮当猫HTML源码
|
1月前
使用html+css制作一个发光立方体特效
使用html+css制作一个发光立方体特效
23 2
使用html+css制作一个发光立方体特效