这是一款基于HTML5的树叶飘落动画,树叶都是图片,并非CSS3绘制,但是树叶飘落的动画效果非常逼真。这款HTML5树叶飘落动画是基于webkit内核的,也就是说要在webkit内核的浏览器上才能使用这款动画。

HTML代码

这是基于webkit的落叶动画

CSS代码#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;

}/* Defines the position and dimensions of the leafContainer div */#leafContainer {    position: absolute;    width: 100%;    height: 100%;

}/* Defines the appearance, position, and dimensions of the message div */#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: 1;

}p {  margin: 15px;

}a{  color: #5C090A;  text-decoration: none;

}/* Sets the color of the "Dino's Gardening Service" message */em {    font-weight: bold;    font-style: normal;

}.phone {  font-size: 150%;  vertical-align: middle;

}/* This CSS rule is applied to all div elements in the leafContainer div.

It styles and animates each leafDiv.

*/#leafContainer > div {    position: absolute;    width: 100px;    height: 100px;    /* We use the following properties to apply the fade and drop animations to each leaf.

Each of these properties takes two values. These values respectively match a setting

for fade and drop.

*/

-webkit-animation-iteration-count: infinite, infinite;    -webkit-animation-direction: normal, normal;    -webkit-animation-timing-function: linear, ease-in;

}/* This CSS rule is applied to all img elements directly inside div elements which are

directly inside the leafContainer div. In other words, it matches the 'img' elements

inside the leafDivs which are created in the createALeaf() function.

*/#leafContainer > div > img {     position: absolute;     width: 100px;     height: 100px;    /* We use the following properties to adjust the clockwiseSpin or counterclockwiseSpinAndFlip

animations on each leaf.

The createALeaf function in the Leaves.js file determines whether a leaf has the

clockwiseSpin or counterclockwiseSpinAndFlip animation.

*/

-webkit-animation-iteration-count: infinite;     -webkit-animation-direction: alternate;     -webkit-animation-timing-function: ease-in-out;     -webkit-transform-origin: 50% -100%;

}/* Hides a leaf towards the very end of the animation */@-webkit-keyframes fade

{    /* Show a leaf while into or below 95 percent of the animation and hide it, otherwise */

0%   { opacity: 1; }

95%  { opacity: 1; }

100% { opacity: 0; }

}/* Makes a leaf fall from -300 to 600 pixels in the y-axis */@-webkit-keyframes drop

{    /* Move a leaf to -300 pixels in the y-axis at the start of the animation */

0%   { -webkit-transform: translate(0px, -50px); }    /* Move a leaf to 600 pixels in the y-axis at the end of the animation */

100% { -webkit-transform: translate(0px, 650px); }

}/* Rotates a leaf from -50 to 50 degrees in 2D space */@-webkit-keyframes clockwiseSpin

{    /* Rotate a leaf by -50 degrees in 2D space at the start of the animation */

0%   { -webkit-transform: rotate(-50deg); }    /*  Rotate a leaf by 50 degrees in 2D space at the end of the animation */

100% { -webkit-transform: rotate(50deg); }

}/* Flips a leaf and rotates it from 50 to -50 degrees in 2D space */@-webkit-keyframes counterclockwiseSpinAndFlip

{    /* Flip a leaf and rotate it by 50 degrees in 2D space at the start of the animation */

0%   { -webkit-transform: scale(-1, 1) rotate(50deg); }    /* Flip a leaf and rotate it by -50 degrees in 2D space at the end of the animation */

100% { -webkit-transform: scale(-1, 1) rotate(-50deg); }

}

JavaScript代码/* Define the number of leaves to be used in the animation */const NUMBER_OF_LEAVES = 30;/*

Called when the "Falling Leaves" page is completely loaded.

*/function init(){    /* Get a reference to the element that will contain the leaves */

var container = document.getElementById('leafContainer');    /* Fill the empty container with new leaves */

for (var i = 0; i

{

container.appendChild(createALeaf());

}

}/*

Receives the lowest and highest values of a range and

returns a random integer that falls within that range.

*/function randomInteger(low, high){    return low + Math.floor(Math.random() * (high - low));

}/*

Receives the lowest and highest values of a range and

returns a random float that falls within that range.

*/function randomFloat(low, high){    return low + Math.random() * (high - low);

}/*

Receives a number and returns its CSS pixel value.

*/function pixelValue(value){    return value + 'px';

}/*

Returns a duration value for the falling animation.

*/function durationValue(value){    return value + 's';

}/*

Uses an img element to create each leaf. "Leaves.css" implements two spin

animations for the leaves: clockwiseSpin and counterclockwiseSpinAndFlip. This

function determines which of these spin animations should be applied to each leaf.

*/function createALeaf(){    /* Start by creating a wrapper div, and an empty img element */

var leafDiv = document.createElement('div');    var image = document.createElement('img');    /* Randomly choose a leaf image and assign it to the newly created element */

image.src = 'images/realLeaf' + randomInteger(1, 5) + '.png';

leafDiv.style.top = "-100px";    /* Position the leaf at a random location along the screen */

leafDiv.style.left = pixelValue(randomInteger(0, 500));    /* Randomly choose a spin animation */

var spinAnimationName = (Math.random()

leafDiv.style.webkitAnimationName = 'fade, drop';

image.style.webkitAnimationName = spinAnimationName;    /* Figure out a random duration for the fade and drop animations */

var fadeAndDropDuration = durationValue(randomFloat(5, 11));    /* Figure out another random duration for the spin animation */

var spinDuration = durationValue(randomFloat(4, 8));    /* Set the -webkit-animation-duration property with these values */

leafDiv.style.webkitAnimationDuration = fadeAndDropDuration + ', ' + fadeAndDropDuration;    var leafDelay = durationValue(randomFloat(0, 5));

leafDiv.style.webkitAnimationDelay = leafDelay + ', ' + leafDelay;

image.style.webkitAnimationDuration = spinDuration;    // add the  to the

leafDiv.appendChild(image);    /* Return this img element so it can be added to the document */

return leafDiv;

}/* Calls the init function when the "Falling Leaves" page is full loaded */window.addEventListener('load', init, false);

android 树叶飘落动画,逼真的HTML5树叶飘落动画相关推荐

  1. html让页面飘树叶的代码,逼真的HTML5树叶飘落动画

    这是一款基于HTML5的树叶飘落动画,树叶都是图片,并非CSS3绘制,但是树叶飘落的动画效果非常逼真.这款HTML5树叶飘落动画是基于webkit内核的,也就是说要在webkit内核的浏览器上才能使用 ...

  2. html 开关窗效果,逼真的HTML5+CSS3窗帘拉开收起动画特效

    逼真的HTML5+CSS3窗帘拉开收起动画特效 html { box-sizing: border-box; } *, *::after, *::before { box-sizing: inheri ...

  3. html酷炫电子时钟效果,逼真的HTML5 canvas模拟时钟特效

    插件描述:thooClock是一款效果非常逼真的HTML5 canvas模拟时钟特效.该时钟特效使用jQuery和HTML5 Canvas API来制作,模拟现实生活中的时钟.并且它还具有定时闹钟的功 ...

  4. html5做动画视频教程,基于HTML5的Flash动画开发视频教程

    (xuehui@TLF) Lynda.com 出品的时长3小时16分的基于HTML5的Flash动画开发视频教程.由Lee Brimelow演示了Flash开发人员在浏览器中利用HTML5,CSS或其 ...

  5. html css动画自动旋转,HTML5 - 用CSS3动画制作场景切换效果(移动,旋转,淡入淡出等)...

    代码如下: HTML5-页面切换动画 #viewsWrapper { top:0px; left:0px; width:300px; height:200px; position:relative; ...

  6. h5画布动画_使用HTML5画布制作动画的漫画面板

    h5画布动画 Continuing the comic theme I've been building over the past few weeks and inspired by the new ...

  7. html5常用动画效果教程,HTML5教程 8个经典HTML5 Canvas动画学习

    本篇教程探讨了HTML5教程 8个经典HTML5 Canvas动画学习,希望阅读本篇文章以后大家有所收获,帮助大家HTML5+CSS3从入门到精通 . < HTML5非常强大,尤其是Canvas ...

  8. HTML5树叶飘落动画

    请使用Chrome浏览器查看本效果. html源代码: Html代码   <!DOCTYPE HTML> <html> <head> <title>HT ...

  9. html5 树叶飘落,使用Html5实现树叶飘落的效果

    实现如图所示的东西效果(落叶下落): html代码: !DOCTYPE htmlhtmlhead titleHTML5树叶飘落动画/title meta charset=utf-8 meta name ...

最新文章

  1. vue 监控元素宽度_Vue入门系列之Vue实例详解与生命周期
  2. ABAP performance学习笔记
  3. Docker 制作自定义化的Tomcat镜像
  4. day19 java数组的常用算法和排序
  5. 嵌入式系统——系统安全之常见病毒漏洞刷题整理
  6. BEM —— 源自Yandex的CSS 命名方法论
  7. 模板函数与模板参数自动推导
  8. 关于Android 启动页加载先预加载系统白页问题
  9. 怎么打开计算机访问权限,怎么打开电脑摄像头权限(摄像头权限5种开启方法)...
  10. elementui 中的 el-descriptions 文字居中显示
  11. 北京邮电大学计算机专业考研复试经验分享
  12. 领英常见问题—如何提高邀请通过率与账号曝光量
  13. 小程序 web-view 打开 微信公众号文章
  14. jQuery基础入门
  15. JAVA10和11什么时候_Java 11 正式发布 支持期限至2026年9月
  16. Fiddler4下载安装和火狐搭配使用
  17. pentaho SPARK
  18. 公博评级06代表什么_钱币公博评级上72(05)什么意思?
  19. [DR吐槽]——三大卡牌链游到底都是什么货色?
  20. thingsboard之边缘网关建立连接过程

热门文章

  1. 终于鸿蒙微内核弄懂了-程序员和鼓励师的合作
  2. 【Spring Security OAuth2笔记系列】- spring security - 图片验证码
  3. Halcon DrawRegion()后会阻塞直到右键按下,请问如何主动取消绘制区域
  4. 序列化和反序列化的概念及应用
  5. Java 之 Serializable 序列化和反序列化的概念,作用的通俗的解释
  6. 飞思卡尔Kinetis系列单片机被锁住后,怎么解锁
  7. Line软件zhuce分析
  8. 普通程序员怎么去【小】厂面试?
  9. css3僵尸走路动画js特效
  10. 关于研究鼠标绘制平滑曲线的阶段总结