Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Your browser doesn't support canvas
css
html, body{ margin:0; padding:0; background-color:hsl(195, 100%, 7%); } #canvas{ margin:0 auto; display:block; filter:url('#shadowed-goo'); } svg{ display:none; }
JavaScript
/** * Constants */ const TWO_PI = Math.PI * 2; /** * Application Class */ class Application { /** * Application constructor */ constructor() { this.canvas = document.getElementById("canvas"); this.context = this.canvas.getContext("2d"); this.width = this.canvas.width = window.innerWidth; this.height = this.canvas.height = window.innerHeight; this.center = { x: this.width / 2, y: this.height / 2 }; this.circleContainers = []; //Resize listener for the canvas to fill browser window dynamically window.addEventListener('resize', () => this.resizeCanvas(), false); } /** * Simple resize function. Reinitializes everything on the canvas while changing the width/height */ resizeCanvas() { this.width = this.canvas.width = window.innerWidth; this.height = this.canvas.height = window.innerHeight; this.center = { x: this.width / 2, y: this.height / 2 }; //Empty the previous container and fill it again with new CircleContainer objects this.circleContainers = []; this.initializeCircleContainers(); } /** * Create a number of CircleContainer objects based on the numberOfContainers variable * @return void */ initializeCircleContainers() { for (let x = 0; x < this.width + 100; x += 100) { for (let y = 0; y < this.height + 100; y += 100) { //Initialize a new instance of the CircleContainer class let circleContainer = new CircleContainer(this.context, x, y); //Let the CircleContainer initialize it's children circleContainer.initializeCircles(); //Add the container to our array of CircleContainer objects this.circleContainers.push(circleContainer); } } } /** * Updates the application and every child of the application * @return void */ update() { for (let i = 0; i < this.circleContainers.length; i++) { this.circleContainers[i].update(); } } /** * Renders the application and every child of the application * @return void */ render() { //Clear the entire canvas every render this.context.clearRect(0, 0, this.width, this.height); //Trigger the render function on every child element for (let i = 0; i < this.circleContainers.length; i++) { this.circleContainers[i].render(); } } /** * Update and render the application at least 60 times a second * @return void */ loop() { this.update(); this.render(); window.requestAnimationFrame(() => this.loop()); } } /** * CircleContainer Class */ class CircleContainer { /** * CircleContainer constructor * @param context - The context from the canvas object of the Application * @param x * @param y */ constructor(context, x, y) { this.context = context; this.position = {x, y}; this.numberOfCircles = 19; this.circles = []; this.baseRadius = 20; this.bounceRadius = 150; this.singleSlice = TWO_PI / this.numberOfCircles; } /** * Create a number of Circle objects based on the numberOfCircles variable * @return void */ initializeCircles() { for (let i = 0; i < this.numberOfCircles; i++) { this.circles.push(new Circle(this.position.x, this.position.y + Math.random(), this.baseRadius, this.bounceRadius, i * this.singleSlice)); } } /** * Try to update the application at least 60 times a second * @return void */ update() { for (let i = 0; i < this.numberOfCircles; i++) { this.circles[i].update(this.context); } } /** * Try to render the application at least 60 times a second * @return void */ render() { for (let i = 0; i < this.numberOfCircles; i++) { this.circles[i].render(this.context); } } } /** * Circle Class */ class Circle { /** * Circle constructor * @param x - The horizontal position of this circle * @param y - The vertical position of this circle * @param baseRadius * @param bounceRadius * @param angleCircle */ constructor(x, y, baseRadius, bounceRadius, angleCircle) { this.basePosition = {x, y}; this.position = {x, y}; this.speed = 0.01; this.baseSize = 10; this.size = 10; this.angle = (x + y); this.baseRadius = baseRadius; this.bounceRadius = bounceRadius; this.angleCircle = angleCircle; } /** * Update the position of this object * @return void */ update() { this.position.x = this.basePosition.x + Math.cos(this.angleCircle) * (Math.sin(this.angle + this.angleCircle) * this.bounceRadius + this.baseRadius); this.position.y = this.basePosition.y + Math.sin(this.angleCircle) * (Math.sin(this.angle + this.angleCircle) * this.bounceRadius + this.baseRadius); this.size = Math.cos(this.angle) * 8 + this.baseSize; this.angle += this.speed; } /** * Renders this Circle object on the canvas * @param context - The context from the canvas object of the Application * @return void */ render(context) { context.fillStyle = "hsl(195, 100%, "+this.size * 4+"%)"; context.beginPath(); context.arc(this.position.x, this.position.y, this.size, 0, TWO_PI); context.fill(); } } /** * Onload function is executed whenever the page is done loading, initializes the application */ window.onload = function () { //Create a new instance of the application const application = new Application(); //Initialize the CircleContainer objects application.initializeCircleContainers(); //Start the initial loop function for the first time application.loop(); };
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>svg海浪动画-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号