html5+css3雪花效果,html5 css3雪花水晶球动画场景特效

html5 css3雪花水晶球动画场景特效,一个漂亮的基于canvas绘制卡通风格水晶球内部下雪动画特效。

c96eb2638dc9e4bbf79583a100bcf0ee.png

查看演示

下载资源:

16

次 下载资源

下载积分:

10

积分

js代码

(function() {

var c1 = document.getElementById("c1");

var c2 = document.getElementById("c2");

var ctx1 = c1.getContext("2d");

var ctx2 = c2.getContext("2d");

c1.height = 300;

c1.width = 300;

c2.height = 300;

c2.width = 300;

ctx1.fillStyle = "white";

ctx2.fillStyle = "white";

var c1Flakes = [];

var c2Flakes = [];

function Flake(r) {

this.x = Math.random() * 300;

this.y = Math.random() * 250;

this.r = r;

}

for (var i = 0; i <= 80; i++) {

var flake = new Flake(2);

c1Flakes.push(flake);

}

for (var i = 0; i <= 80; i++) {

var flake = new Flake(3);

c2Flakes.push(flake);

}

function render() {

ctx1.clearRect(0, 0, 300, 300);

ctx2.clearRect(0, 0, 300, 300);

for (var i = 0; i < c1Flakes.length; i++) {

ctx1.beginPath();

ctx1.arc(c1Flakes[i].x, c1Flakes[i].y, c1Flakes[i].r, 0, Math.PI * 2);

ctx1.fill();

if (c1Flakes[i].y <= 245){

c1Flakes[i].y+= .3;

}

else{

c1Flakes[i].y = 0;

}

}

for (var i = 0; i < c2Flakes.length; i++) {

ctx2.beginPath();

ctx2.arc(c2Flakes[i].x, c2Flakes[i].y, c2Flakes[i].r, 0, Math.PI * 2);

ctx2.fill();

if (c2Flakes[i].y <= 245){

c2Flakes[i].y += .6;

}

else{

c2Flakes[i].y = 0;

}

}

requestAnimationFrame(render);

}

render();

})();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值