HTML5+Webkit怎么实现树叶飘落动画

这篇文章主要讲解了“HTML5+Webkit怎么实现树叶飘落动画”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“HTML5+Webkit怎么实现树叶飘落动画”吧!

创新互联建站主打移动网站、成都做网站、网站建设、外贸营销网站建设、网站改版、网络推广、网站维护、域名与空间、等互联网信息服务,为各行业提供服务。在技术实力的保障下,我们为客户承诺稳定,放心的服务,根据网站的内容与功能再决定采用什么样的设计。最后,要实现符合网站需求的内容、功能与设计,我们还会规划稳定安全的技术方案做保障。

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

HTML5+Webkit怎么实现树叶飘落动画 

html代码:




    HTML5树叶飘落动画
    
    
    
    


    
        
                     这是基于webkit的落叶动画         
    
   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: 1; } 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: 1; }     95%  { opacity: 1; }     100% { opacity: 0; } } @-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);

PS:下面看下html5 canvas处理连续帧图片,下面的代码基于IE8以上






Canvas Demo



    

感谢各位的阅读,以上就是“HTML5+Webkit怎么实现树叶飘落动画”的内容了,经过本文的学习后,相信大家对HTML5+Webkit怎么实现树叶飘落动画这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!


网站题目:HTML5+Webkit怎么实现树叶飘落动画
标题链接:http://scjbc.cn/article/jgsodj.html

其他资讯