您现在的位置是:网站首页> 编程资料编程资料
基于HTML5+Webkit实现树叶飘落动画html5结合Canvas实现的树叶飘落动画特效源码逼真的HTML5树叶飘落动画HTML5实现的树叶飘落动画特效源码
2021-08-31
1106人已围观
简介 本文给大家分享一段实例代码给大家介绍基于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图表的示例
- Html5百叶窗效果的示例代码html5实现点击弹出图片功能html5 录制mp3音频支持采样率和比特率设置html5表单的required属性使用html5调用摄像头实例代码HTML5页面音频自动播放的实现方式Html5大屏数据可视化开发的实现html实现弹窗的实例HTML5来实现本地文件读取和写入的实现方法HTML 罗盘式时钟的实现HTML5简单实现添加背景音乐的几种方法
- 详解如何通过H5(浏览器/WebView/其他)唤起本地apphtml5唤起app的方法
- iphoneX 适配客户端H5页面的方法教程有关HTML5页面在iPhoneX适配问题适配iPhone X要点:十分钟快速掌握iPhone X UI界面适配技巧
- 详解H5 活动页之移动端 REM 布局适配方法Html5移动端适配IphoneX等机型的方法rem适配移动设备的方法示例浅谈移动端适配大法详解如何使用image-set适配移动端高清屏图片移动 web 端屏幕适配(rem)html5实现移动端适配完美写法手机端用rem+scss做适配的详解移动端适配 使px自动转换rem
- HTML5 canvas 瀑布流文字效果的示例代码HTML5播放实现rtmp流直播html5用video标签流式加载的实现基于 HTML5 WebGL 实现的医疗物流系统Html5 实现微信分享及自定义内容的流程HTML5移动端手机网站开发流程HTML5实现的图片无限加载的瀑布流效果另带边框圆角阴影HTML5梦幻之旅——炫丽的流星雨效果实现过程HTML5 离线应用之打造零请求、无流量网站的解决方法Html5之webcoekt播放JPEG图片流
