这是一款基于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 < NUMBER_OF_LEAVES; 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() < 0.5) ? 'clockwiseSpin' : 'counterclockwiseSpinAndFlip';

/* Set the -webkit-animation-name property with these values */

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);

html让页面飘树叶的代码,逼真的HTML5树叶飘落动画相关推荐

  1. android 树叶飘落动画,逼真的HTML5树叶飘落动画

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

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

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

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

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

  4. html5时钟代码菜鸟课程,html5绘制时钟动画

    这篇文章主要介绍了html5绘制时钟动画,需要的朋友可以参考下 复制代码代码如下: var clock=document.getElementById("clock"); var ...

  5. html 转图片 wekit实现,HTML5和Webkit实现树叶飘落动画

    HTML5和Webkit在一起会实现什么样的动画呢?本文给大家分享一段实例代码给大家介绍基于HTML5 Webkit实现树叶飘落动画效果,需要的朋友参考下吧,希望能帮组到大家. 实现如图所示的东西效果 ...

  6. HTMl页面加入落叶下雨动画,基于HTML5+Webkit实现树叶飘落动画

    实现如图所示的东西效果(落叶下落): html代码: HTML5树叶飘落动画 这是基于webkit的落叶动画 css代码: body{ background-color: #4E4226; } #co ...

  7. HTMl页面加入落叶下雨动画,HTML5和Webkit实现树叶飘落动画

    HTML5和Webkit在一起会实现什么样的动画呢?本文给大家分享一段实例代码给大家介绍基于HTML5+Webkit实现树叶飘落动画效果,需要的朋友参考下吧,希望能帮组到大家. 实现如图所示的东西效果 ...

  8. 在ASP.NET中指定出错页面,不让代码外泄!

    在ASP.NET中指定出错页面,不让代码外泄!在ASP.NET中原始的出错页面会暴露部分源代码,由此带来了潜在的安全隐患. ASP.NET允许应用程序出错时显示用户指定的页面,方法是在web.conf ...

  9. .Net有关问题。在GridView中添加了一个HyperLinkField,用来显示显示详细信息,请教跳转后的详细信息页面该怎样写代码

    .Net问题...在GridView中添加了一个HyperLinkField,用来显示显示详细信息,请问跳转后的详细信息页面该怎样写代码 在一个页面的GridView中添加了下面的代码: <as ...

最新文章

  1. Linux文件夹共享(NFS)
  2. Mentor PADS 9.5下载安装及破解指南
  3. Rails开发细节《一》
  4. 第一届大数据科学与工程国际会议(2016)征文通知
  5. mysql索引类型 优劣_Mysql索引的类型和优缺点详解
  6. 2017.3.12 分割矩阵 失败总结
  7. 阿里巴巴张勇:创造风口而不是追逐
  8. html怎么隐藏y方向内容,如何隐藏scroll-Y纵向滚动条,并不影响内容滚动的方法...
  9. 一种基于SoC和阿里云的智能家居系统设计方案_家电研究报告
  10. 带界面的程序化交易软件-从今天开始
  11. word中表格剩最后一行,一旦超过两行自动跳到下一页
  12. 总听大佬说起数字化转型,但你真正理解什么是数字化吗?( 2017-02-14 大愚若智 译 )
  13. 高防CDN在防御DDoS攻击中必不可少?简析高防CDN针对防御DDoS攻击的可行方案
  14. 《新神榜:杨戬》这样的爆款影视动漫作品,原来都掌握了一个成功密码
  15. BoomBoomBoom
  16. D23:Multiple of 3 Or 5(3或5的倍数,翻译+题解)
  17. Windows下Jrtplib的使用
  18. 洛谷[P1719 最大加权矩形] {前缀和与差分} 奋斗的珂珂~
  19. Android课设——理财小助手
  20. KOA中await next分析?

热门文章

  1. 利用python抓取搜狗指数学习笔记
  2. 人机料法环,最全质量管理方法都在这儿!
  3. DCT变换-----学习笔记
  4. c语言编程六度空间,六度空间理论的图论法证明及应用
  5. 今日趣闻|互联网寒潮中的面试...
  6. 微软将裁员1.8万人
  7. 八一农垦大学计算机科学与技术专业好不好,黑龙江八一农垦大学最好的专业(什么专业最好)...
  8. 第7期:内卷和躺平,你怎么选
  9. word标题和目录制作方法
  10. Vue_插槽_自定义指令_tabbar案例