您现在的位置是:网站首页> 编程资料编程资料
基于HTML5+Webkit实现树叶飘落动画html5结合Canvas实现的树叶飘落动画特效源码逼真的HTML5树叶飘落动画HTML5实现的树叶飘落动画特效源码
2023-10-13
411人已围观
简介 本文给大家分享一段实例代码给大家介绍基于HTML5+Webkit实现树叶飘落动画效果,需要的朋友参考下吧
实现如图所示的东西效果(落叶下落):
html代码:
HTML5树叶飘落动画 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);这是基于webkit的落叶动画
PS:下面看下html5 canvas处理连续帧图片,下面的代码基于IE8以上
Canvas Demo
总结
以上所述是小编给大家介绍的基于HTML5+Webkit实现树叶飘落动画,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
相关内容
- HTML5 解决苹果手机不能自动播放音乐问题html5 video全屏播放/自动播放的实现示例html5中嵌入视频自动播放的问题解决html5自动播放mov格式视频的实例代码解决HTML5中的audio在手机端和微信端的不能自动播放问题有关HTML5中背景音乐的自动播放功能HTML5页面音视频在微信和app下自动播放的实现方法HTML5页面音频自动播放的实现方式
- canvas实现圆形进度条动画的示例代码HTML5 Canvas 实现圆形进度条并显示数字百分比效果示例
- 详解HTML5 录音的踩坑之旅HTML5网页录音和上传到服务器支持PC、Android,支持IOS微信功能html5录音功能实战示例HTML5录音实践总结(Preact)
- 移动HTML5前端框架—MUI的使用mui几种页面跳转方式对比总结概括
- canvas如何绘制钟表的方法html5中canvas图表实现柱状图的示例基于HTML5 Canvas的3D动态Chart图表的示例
- 全民英雄小小进化品质及升级条件说明 全民英雄小小怎么进化_手机游戏_游戏攻略_
- 全民英雄如何扩展酒馆 全民英雄提高酒馆上限方法攻略_手机游戏_游戏攻略_
- 全民英雄控制英雄全面解析 全民英雄控制英雄有哪些_手机游戏_游戏攻略_
- 全民英雄蓝卡攻略心得及全民英雄光法的细节_手机游戏_游戏攻略_
- 全民英雄最强英雄排行一览 全民英雄紫卡技能属性数据排行_手机游戏_游戏攻略_
