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

简介: 本文分享几种基于HTML5+CSS3实现的一些动画特效:图片旋转、无限滚动、文字跳动;实现起来均比较容易,动手来试试! 一、图片旋转 效果图如下: 这个效果实现起来其实并不困难。代码清单如下: #liu{ width:280px; ...

本文分享几种基于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操作之后,他们会变成块级元素。

相关文章
|
1月前
|
移动开发 JavaScript 前端开发
【Html.js——图片折叠效果】折叠手风琴(蓝桥杯真题-1763)【合集】
本项目实现了一个图片折叠手风琴效果,使用jQuery完成。主要包括以下部分: - **介绍**:任务是通过点击图片实现折叠和展开的效果。 - **准备**:内置初始代码,包含 `css/style.css`、`images/` 文件夹、`js/` 文件夹及 `index.html` 等文件。启动 Web Server 服务可运行项目。 - **目标**:完善 `index.js` 文件,使页面达到预期的折叠效果。 - **规定**:严格按步骤操作,保持默认文件结构不变,并在完成后保持 Web 服务正常访问状态。 - **通关代码**:使用 jQuery 实现点击事件,为选中元素添加 `act
45 19
|
3月前
利用html2canvas插件自定义生成名片信息并保存图片
这是一个利用html2canvas插件自定义生成名片信息并保存图片,自定义上传头像,自定义输入个人信息内容,自定义图片名称,并将生成的图片保存到本地
68 1
利用html2canvas插件自定义生成名片信息并保存图片
|
7月前
|
移动开发 前端开发 JavaScript
基于 HTML5 和 Canvas 开发的在线图片编辑器
基于 HTML5 和 Canvas 开发的在线图片编辑器
137 0
|
4月前
HTML图片
【10月更文挑战第4天】HTML图片。
50 2
|
5月前
|
前端开发
Twaver-HTML5基础学习(37)network导出图片并下载
本文介绍了如何在Twaver-HTML5中将network导出为图片并提供下载,主要通过将network转换为canvas对象,然后转换为base64编码的图片进行展示和下载。
61 5
|
9月前
|
移动开发
uni-app使用v-html输出富文本图片溢出解决
uni-app使用v-html输出富文本图片溢出解决
767 1
|
5月前
|
前端开发 Windows
【前端web入门第一天】02 HTML图片标签 超链接标签 音频标签 视频标签
本文档详细介绍了HTML中的图片、超链接、音频和视频标签的使用方法。首先讲解了`&lt;img&gt;`标签的基本用法及其属性,包括如何使用相对路径和绝对路径。接着介绍了`&lt;a&gt;`标签,用于创建超链接,并展示了如何设置目标页面打开方式。最后,文档还涵盖了如何在网页中嵌入音频和视频文件,包括简化写法及常用属性。
88 13
|
6月前
在线将多张图片拼接起来图工具HTML源码
在线将多张图片拼接成一张图片,多图合一并导出下载。无需本地安装软件。 下载时,使用日期时间作为文件名,规避图片文件名相同造成的覆盖问题;也能省去一部覆盖确认操作 多语言支持
67 0
在线将多张图片拼接起来图工具HTML源码
|
6月前
|
Python
Python 下载 html 中的 图片
Python 下载 html 中的 图片
65 2
|
7月前
|
数据采集 缓存 自然语言处理
PHP将HTML标签转化为图片
通过这个方法,PHP后端能够实现将HTML内容转化为图片的功能。这种方式虽然牵涉到一些额外的安装和配置,但能够相对灵活且稳定地解冀转换需求,适用于需要在后端动态生成图片的场景。
286 1