87,907
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>HTML5 Canvas</title>
<style type="text/css">
*{ margin: 0; padding: 0; font-size: 1em; }
body{ background: #eee; }
canvas{ display: block; border: 4px solid #f90; background: #fff; margin: 0 auto; }
h2{ font-size: 2em; text-align: center; line-height: 2; color: #f60; }
</style>
</head>
<body>
<h2 id="data">data</h2>
<canvas width="880" height="330" id="cvs"></canvas>
<script type="text/javascript">
function obj(id){ return document.getElementById(id); }
function imgLoad(url){
var img=new Image();
img.onload=function(){
img.onload=null;
};
img.src=url;
return img;
}
var img_1=imgLoad("http://mozorg.cdn.mozilla.net/media/img/firefoxos/example-apps.jpg");
var img_2=imgLoad("http://mozorg.cdn.mozilla.net/media/img/firefoxos/example-videos.jpg");
var img_3=imgLoad("http://mozorg.cdn.mozilla.net/media/img/firefoxos/example-browser.jpg");
var img_4=imgLoad("http://mozorg.cdn.mozilla.net/media/img/firefoxos/example-gallery.jpg");
var imgs=[img_1,img_2,img_3,img_4];
var cvs=obj("cvs");
var ctx=cvs.getContext("2d");
var data=obj("data");
var ctxAs=0;
var ctxAe=1;
var ctxN=0;
function cvsAm(){
if(ctxAs<ctxAe){
ctx.clearRect(0,0,cvs.width,cvs.height);
ctx.save();
ctx.globalAlpha=ctxAs;
ctx.drawImage(imgs[ctxN],0,0);
ctx.restore();
ctxAs+=0.1;
setTimeout(cvsAm,400);
}
}
function cvsTog(){
if(ctxN<imgs.length){
data.innerHTML="Canvas Bg: "+ctxN;
cvsAm();
// ctxAs=0;
ctxN++;
}else{
ctxN=0;
}
}
window.onload=function(){
setInterval(cvsTog,2000);
};
</script>
</body>
</html>
u:function(){
if(++this.alpha>this.maxAlpha){
this.alpha = 0;
if(++this.nowindex>=this.imgs.length){this.nowindex = 0}
if(++this.nextindex>=this.imgs.length){this.nextindex = 0}
}
return this;
}
这个方法里面:if(++this.alpha>this.maxAlpha)这样的判断方式按照正常写法应该怎么写?