资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

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如何实现树叶飘落动画-创新互联
文章起源:http://cdkjz.cn/article/dhddid.html
返回首页 了解更多建站资讯
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220