无插件HTML,无插件 HTML5 雪花特效

上代码:->

* {margin:0px;

padding:0px;}

body, html {width:100%;

height:100%; overflow:hidden;}

function jDrawSnow(){

var myCanvas =

document.getElementByIdx_x('mycanvas');

var cxt =

myCanvas.getContext('2d');

var snowcount = 200; ///

显示数量

var index = 0;

var randomNum =

0;//随机数

var zoo = 0;

var rheiNum = 0;

imageList = {}; ///

图片列表

imageSource =

['blue_glow.jpg', 'snow3.png']; /// 图片源文件类表

var snowlist = [];

/// 初始化

function init() {

/// 画布

myCanvas.width =

document.body.offsetWidth;

myCanvas.height =

document.body.offsetHeight;

zoo =

parseInt(Math.random() * 2);

if(zoo == 1){

randomNum = 0.7;

}else{

randomNum = 0.5;

}

// 加载图片

loadImages();

}

/// 加载图片

function loadImages()

{

for (var i in imageSource)

{

imageList[i] = new

Image();

imageList[i].src =

imageSource[i];

imageList[i].onload =

function () {

index++;

if (imageSource.length

>= index++) {

callImages();

}

}

}

}

function callImages()

{

for (var i = 0; i <

snowcount; i++) {

snowlist.push(new

snow());

}

setInterval(function ()

{

cxt.clearRect(0, 0,

myCanvas.width, myCanvas.height);//清空

fillBackground();//填充背景

for (var i in snowlist)

{

snowlist[i].Go();

if (snowlist[i].Y >=

myCanvas.height) {//重置雪花

snowlist[i] = new

snow();

}

}

}, 20);

}

function fillBackground()

{

cxt.drawImage(imageList[0],

0, 0, imageList[0].width, imageList[0].height, 0,0, myCanvas.width,

myCanvas.height);

}

/// 雪

function snow()

{

this.X =

parseInt(Math.random() * myCanvas.width);

if( rheiNum <=

snowcount){

this.Y =

parseInt(Math.random() * myCanvas.height);

rheiNum += 1;

}else{

this.Y = 0;

}

this.Size =

parseInt(Math.random() * 30);

this.Transparency =

10;

this.Speed =

parseInt(Math.random()*(1-10+1)+9);

}

/// 动起来

snow.prototype.Go =

function () {

this.Y  =

this.Y + this.Speed;

var xNum = 0;

if(randomNum == 0.5){

this.X = this.X + randomNum

;

xNum = 125;

}else {

this.X = this.X -

randomNum;

xNum = -125;

}

var borderLine =

imageList[1].width-55 - this.Size;

cxt.drawImage(imageList[1],

0, 0, imageList[1].width, imageList[1].height, this.X - xNum,

this.Y , borderLine , borderLine);

}

init();

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值