实现如图所示的东西效果(落叶下落):

html代码:

<!DOCTYPE html>
<html>
<head>
<title>HTML5树叶飘落动画</title>
<meta charset="utf-8">
<meta name="viewport" content="width=500px, initial-scale=0.64">
<link rel="stylesheet" href="leaves.css" type="text/css">
<script src="leaves.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="leafContainer"></div>
<div id="message">
<em>这是基于webkit的落叶动画</em>
</div>
</div>
</body>
</html>

css代码:

body
{
background-color: #4E4226;
} #container {
position: relative;
height: 700px;
width: 500px;
margin: 10px auto;
overflow: hidden;
border: 4px solid #5C090A;
background: #4E4226 url('images/backgroundLeaves.jpg') no-repeat top left;
} #leafContainer {
position: absolute;
width: 100%;
height: 100%;
} #message{
position: absolute;
top: 160px;
width: 100%;
height: 300px;
background:transparent url('images/textBackground.png') repeat-x center;
color: #5C090A;
font-size: 220%;
font-family: 'Georgia';
text-align: center;
padding: 20px 10px;
-webkit-box-sizing: border-box;
-webkit-background-size: 100% 100%;
z-index:;
} em {
font-weight: bold;
font-style: normal;
} #leafContainer > div {
position: absolute;
width: 100px;
height: 100px;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: normal;
-webkit-animation-timing-function: linear;
} #leafContainer > div > img {
position: absolute;
width: 100px;
height: 100px;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
-webkit-animation-timing-function: ease-in-out;
-webkit-transform-origin: 50% -100%;
} @-webkit-keyframes fade
{
0% { opacity:; }
95% { opacity:; }
100% { opacity:; }
} @-webkit-keyframes drop
{
0% { -webkit-transform: translate(0px, -50px); }
100% { -webkit-transform: translate(0px, 650px); }
} @-webkit-keyframes clockwiseSpin
{
0% { -webkit-transform: rotate(-50deg); }
100% { -webkit-transform: rotate(50deg); }
} @-webkit-keyframes counterclockwiseSpinAndFlip
{
0% { -webkit-transform: scale(-1, 1) rotate(50deg); }
100% { -webkit-transform: scale(-1, 1) rotate(-50deg); }
}

js代码:

const NUMBER_OF_LEAVES = 30;
function init(){
var container = document.getElementById('leafContainer');
for (var i = 0; i < NUMBER_OF_LEAVES; i++) {
container.appendChild(createALeaf());
}
} function randomInteger(low, high){
return low + Math.floor(Math.random() * (high - low));
} function randomFloat(low, high){
return low + Math.random() * (high - low);
} function pixelValue(value){
return value + 'px';
} function durationValue(value){
return value + 's';
} function createALeaf(){
var leafDiv = document.createElement('div');
leafDiv.style.top = "-100px";
leafDiv.style.left = pixelValue(randomInteger(0, 500));
leafDiv.style.webkitAnimationName = 'fade, drop';
var fadeAndDropDuration = durationValue(randomFloat(5, 11));
leafDiv.style.webkitAnimationDuration = fadeAndDropDuration + ', ' + fadeAndDropDuration;
var leafDelay = durationValue(randomFloat(0, 5));
leafDiv.style.webkitAnimationDelay = leafDelay + ', ' + leafDelay; var image = document.createElement('img');
image.src = 'images/realLeaf' + randomInteger(1, 5) + '.png';
var spinAnimationName = (Math.random() < 0.5) ? 'clockwiseSpin' : 'counterclockwiseSpinAndFlip';
image.style.webkitAnimationName = spinAnimationName;
var spinDuration = durationValue(randomFloat(4, 8));
image.style.webkitAnimationDuration = spinDuration; leafDiv.appendChild(image);
return leafDiv;
} window.addEventListener('load', init, false);

转载地址:http://www.html5tricks.com/css3-fall-leaves.html

HTML5效果:实现树叶飘落的更多相关文章

  1. HTML5树叶飘落动画

    查看效果:http://keleyi.com/keleyi/phtml/css3/15.htm 请使用Chrome浏览器查看本效果. html源代码: <!DOCTYPE HTML> &l ...

  2. cocos2d-x 仿真树叶飘落效果的实现

    转自:http://blog.csdn.net/ufolr/article/details/7624851 最近项目中需要一个落叶的效果,本来想用粒子特效来实现,但是几经调试,虽然调出了落叶的效果,但 ...

  3. <转>cocos2d-x学习笔记(五)仿真树叶飘落效果的实现(精灵旋转、翻转、钟摆运动等综合运用)

    转载自ufolr的博客 原文连接:http://blog.csdn.net/ufolr/article/details/7624851 最近项目中需要一个落叶的效果,本来想用粒子特效来实现,但是几经调 ...

  4. 精选9个值得学习的 HTML5 效果【附源码】

    这里精选了一组很酷的 HTML5 效果.HTML5 是现 Web 开发领域的热点, 拥有很多让人期待已久的新特性,特别是在移动端,Web 开发人员可以借助 HTML5 强大功能轻松制作各种交互性强.效 ...

  5. 精选9个值得学习的 HTML5 效果

    此文转自:http://www.cnblogs.com/lhb25/p/9-html5-effects.html,仅供本人学习参考,版权归原作者所有! 精选9个值得学习的 HTML5 效果[附源码] ...

  6. HTML5 canvas绘制雪花飘落动画(需求分析、知识点、程序编写分布详解)

    看到网上很多展示html5雪花飞动的效果,确实非常引人入胜,我相信大家也跟我一样看着心动的同时,也很好奇,想研究下代码如何实现:虽然哦很多地方也能下载这些源码,不过也不知道别人制作此类动画时的思路及难 ...

  7. HTML5 canvas绘制雪花飘落

    Canvas是HTML5新增的组件,它就像一块幕布,可以用JavaScript在上面绘制各种图表.动画等. 没有Canvas的年代,绘图只能借助Flash插件实现,页面不得不用JavaScript和F ...

  8. 推荐六款炫酷的HTML5效果插件

    1. HTML5 3D图片阴影翻转动画 效果很酷 分享一款很酷的HTML5 3D动画特效,这款3D特效可以为你的图片增加阴影的效果,而且可以让图片在鼠标滑过的时候出现3D翻转的动画效果.这和HTML5 ...

  9. HTML5效果:Canvas 实现圆形进度条并显示数字百分比

    实现效果 1.首先创建html代码 <canvas id="canvas" width="500" height="500" styl ...

随机推荐

  1. eclipse对于标签的配置不会出现自动提示的解决

    解决办法:引入 mybatis-3-config.dtd 文件Window-preferences-搜索 xml-xml catalog在 User Specified Entries 目录下 add ...

  2. Spring Boot 2.x 启动全过程源码分析(上)入口类剖析

    Spring Boot 的应用教程我们已经分享过很多了,今天来通过源码来分析下它的启动过程,探究下 Spring Boot 为什么这么简便的奥秘. 本篇基于 Spring Boot 2.0.3 版本进 ...

  3. tensorflow笔记4:函数:tf.assign()、tf.assign_add()、tf.identity()、tf.control_dependencies()

    函数原型: tf.assign(ref, value, validate_shape=None, use_locking=None, name=None)   Defined in tensorflo ...

  4. @vue/cli 构建得项目eslint配置2

    使用ESLint+Prettier来统一前端代码风格 加分号还是不加分号?tab还是空格?你还在为代码风格与同事争论得面红耳赤吗? 正文之前,先看个段子放松一下: 去死吧!你这个异教徒! 想起自己刚入 ...

  5. RocketMQ

    http://rocketmq.apache.org/docs/quick-start/ 解压后添加启动脚本 nohup sh bin/mqnamesrv >> logs/namesrv. ...

  6. 整理一下pywinauto 的sendeys(py2.7)换成python3.6用PyUserInput

    没办法入门学的是py3.6所以有些只支持2.7的库保好放弃了 senkeys (2.7)==>pyuserinput (3.6) ================================ ...

  7. [python]使用virtualenvWrapper

    什么是virtualenv virtualenv是python的环境管理工具,用于隔离python的运行环境.也就是说,一个项目可以有一个属于这个项目的运行环境,从而避免了因为依赖不同的模块而产生的错 ...

  8. 记一次安装Ipython的流程

    这是一个悲伤的安装ipython的过程. 写下来留个教训吧. 也是希望对博友一些帮助吧. 注: 我也写了一篇window下安装bpython的文章(个人感觉bpython要比ipython强大的多), ...

  9. SOAP报文转成JAVA对象

    在今天以前我还没有用过代码解析过SOAP报文,更别提转成JAVA对象了,今天的任务中报文这个模样的,(为防止数据信息,以下数据我故意打乱了防止泄露什么信息.) <?xml version=&qu ...

  10. Mybatis的原理相关

    今天看了一篇有关Mybatis非常好的文章,顺便写了一下学习心得. 原文地址:https://blog.csdn.net/u010349169/article/details/40422941 一.M ...