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

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. 第一节:学会Java前提-手把手教你配置JDK环境变量

    前言 大家好,今天写一遍学会Java前提-手把手教你配置JDK环境变量的概述,希望你们喜欢 下载地址 下载jdk,和eclipse就比较简单了,提供JDK 9 地址: http://www.oracl ...

  2. [Swift]枚举类型:UIBarButtonItem的24种样式

    UIBarButtonSystemItemFlexibleSpace 可变空白, 在调用的过程中,使用  UIBarButtonSystemItemFlexibleSpace去占位,达到实现规范化的目 ...

  3. JMH实践-代码性能测试工具

    概述 JMH,即Java Microbenchmark Harness,是专门用于代码微基准测试的工具套件 JMH比较典型的应用场景有: 想准确的知道某个方法需要执行多长时间,以及执行时间和输入之间的 ...

  4. Redis学习笔记之Redis基本数据结构

    Redis基础数据结构 Redis有5种基本数据结构:String(字符串).list(列表).set(集合).hash(哈希).zset(有序集合) 字符串string 字符串类型是Redis的va ...

  5. MySql必备技能 不会的赶紧get一下 可以说很详细了

    1.Mysql服务 mysql服务如何开启: 下载了mysql数据库你的服务中会有mysql服务. 1.1: 1.2: 2.使用sql语句进行 建库.建表.等操作. 2.1:使用sql语句进行创建数据 ...

  6. MyBatis 延迟加载的三种加载方式深入,你get了吗?

    延迟加载 延迟加载对主对象都是直接加载,只有对关联对象是延迟加载. 延迟加载可以减轻数据库的压力, 延迟加载不可是一条SQL查询多表信息,这样构不成延迟加载,会形成直接加载. 延迟加载分为三种类型: ...

  7. 使用线程统计信息(Thread Statistics)

    可在session log中使用线程统计信息来判断source,target或组的性能瓶颈 默认情况下,Integration Service在运行session时,使用一个reader thread ...

  8. Git基本命令 -- 历史

    历史. 收先需要了解一下git log命令, 使用git的帮助看看: git help log: 执行该命令后, 我的win10弹出来一个html页面, 里面是git log命令的帮助: 首先看看gi ...

  9. vue 项目实战 (生命周期钩子)

    开篇先来一张图 下图是官方展示的生命周期图 Vue实例的生命周期钩子函数(8个)        1. beforeCreate             刚 new了一个组件,无法访问到数据和真实的do ...

  10. PHP源码阅读(一):str_split函数

    注:源码版本:php5.6.33. 函数简介 str_split 原型: array str_split ( string $string [, int $split_length = 1 ] ) 说 ...