html5 白云,html5绘制一朵逼真的白云动画特效

html5绘制一朵逼真的白云动画特效,蓝蓝的天空中一朵白色模糊云朵飘动着。

8e06c2e3819b56cf38e7bd6c9c85df93.png

查看演示

下载资源:

11

次 下载资源

下载积分:

10

积分

js代码

var Cloud = {};

Cloud.init = function() {

this.width = window.innerWidth;

this.height = window.innerHeight;

this.xC = this.width / 2;

this.yC = this.height / 2;

this.stepCount = 0;

this.population = 200;

this.particles = [];

for (var i = 0; i < this.population; i++) {

Cloud.birth();

}

};

Cloud.evolve = function() {

this.stepCount++;

this.move();

this.draw();

};

Cloud.move = function() {

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

var p = this.particles[i];

p.x = p.xStart + p.dist * Math.cos(p.speed * this.stepCount);

p.y = p.yStart + p.dist * Math.sin(p.speed * this.stepCount);

}

};

Cloud.draw = function() {

var divs = document.getElementsByClassName('drop');

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

var particle = this.particles[i],

div = divs[i];

var r = particle.r,

x = particle.x - r / 2,

y = particle.y - r / 2;

div.style.left = x + 'px';

div.style.top = y + 'px';

div.style.height = particle.r + 'px';

div.style.width = particle.r + 'px';

}

};

Cloud.birth = function() {

var speed = 0.2,

x = this.xC + 220 * (-1 + 2 * Math.random()),

y = this.yC + 100 * (-1 + 2 * Math.random()),

minSize = 10,

maxSize = 150,

distToCenter = Math.sqrt(Math.pow(x - this.xC, 2) + Math.pow(y - this.yC, 2)),

size = 170 - 0.65 * distToCenter;

// Create new particle

var particle = {

x: x,

y: y,

xStart: x,

yStart: y,

speed: speed * (-0.5 + Math.random()),

dist: 15,

r: size

};

// Push new particle to global particles array

this.particles.push(particle);

// Create one more div node and append to DOM

var div = document.createElement('div');

div.className = 'drop';

document.getElementsByTagName('body')[0].appendChild(div);

};

document.addEventListener('DOMContentLoaded', function() {

Cloud.init();

setInterval(function() {

Cloud.evolve();

}, 50);

});

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值