JavaScript实现飞舞的泡泡效果
本文实例为大家分享了JavaScript实现飞舞泡泡效果的具体代码,供大家参考,具体内容如下
示例
CSS
html, body{ margin:0; padding:0; width:100%; height:100%; } canvas{ position:fixed; width:100%; height:100%; }
JS
constnbObjects=800; varconf,scene,camera,cameraCtrl,light,renderer; varwhw,whh; varobjects; varspriteMap,spriteMaterial; varmouse=newTHREE.Vector2(); varmouseOver=false; varmousePlane=newTHREE.Plane(newTHREE.Vector3(0,0,1),0); varmousePosition=newTHREE.Vector3(); varraycaster=newTHREE.Raycaster(); functioninit(){ conf={ opacity:0.8 }; scene=newTHREE.Scene(); camera=newTHREE.PerspectiveCamera(100,window.innerWidth/window.innerHeight,0.1,1000); cameraCtrl=newTHREE.OrbitControls(camera); cameraCtrl.autoRotate=true; cameraCtrl.autoRotateSpeed=5; renderer=newTHREE.WebGLRenderer(); renderer.setSize(window.innerWidth,window.innerHeight); document.body.appendChild(renderer.domElement); initScene(); onWindowResize(); window.addEventListener('resize',onWindowResize,false); animate(); }; functioninitScene(){ scene=newTHREE.Scene(); scene.background=newTHREE.Color(0xFFF8DC); camera.position.z=30; camera.position.y=20; camera.lookAt(0,0,0); spriteMap=newTHREE.Texture(); varbubble=newImage(); bubble.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAAuXSURBVHjahFdrrKXVWX7etda3vsveZ+99zj5zzlyYOzNDh+kUGILS2pgCBWsFW0qsjUYdW2JsJGqi0Qab8ENjUmNimpi2xssPSmtBg/xoaKFyGWKwMAzMMA0F5nbm3M+efc6+fpd1e/1xBnVKjW+ysrLWj/U8edeT931eAhjXxFYAWwBcAlAC+AKAh4GpdICfGeT7j4Fu+pALRw4G7FcxTQshNAwPzwsx95rCGy8TnTxRi8/m704ALwL4ewDvALju6ntX8JPB167G1f0zDLz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Y64g22yAzyMda8cxkXeyYauitrXp8eNfs7F037P3Y9iK/5xu11Rcf5n1/VP7mdRt4+Vo4CTzyPycFYBmwb9Sq7+xLv13eOJz4+Zr95LZ1t30jt7210bhfGuMACkpS0FKGWqp5tlWnfTOt+PDOLc1j+7dv//ih3R/9SKv2q1fijV1fkqOv//X8kT9zD86UOPm+wfQnMqAA6E094CyAB4B9X+wc+tzB7q8cXlndW55YKueX+ytrxJ0qS/J6GodGLdX1NK63SbRnGNsnUjmzfiBzz1L8w8fnW4+tX7h+AV8FsHYVo///EYgA3AXgVQArAHYCuANo/8Jw600H12/eut7ZVl/oTCS9USoEJTqSOlaSx/WsXJ6c6Pw4qZ0/vdh+xc9t6+MlAOOr+qoAzAEYXkvgvwYAeZXc4usq26IAAAAASUVORK5CYII="; bubble.onload=function(){ spriteMap.image=bubble; spriteMap.needsUpdate=true; }; objects=[]; for(vari=0;i以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。