编辑︰这得到了太复杂的方式,我将迁移这个问题到另一个问题,并把我的新代码在那里!请忽略此代码,因为它在逻辑上存在缺陷。 (请投票关闭的问题,因为它是没有意义的)JavaScript语法疑问? (mootools)
嗨,
我初始化下面的循环在我的代码。代码是使用mootools编写的。
CANVAS.init({ canvasElement : 'canvas', interactive : true });
var itemlayer = CANVAS.layers.add({ id : 'items' });
for(var j = 0; j < 5; j++)
{
for(var i = 0; i < 5; i++)
{
itemlayer.add({
id : 'item-'+i + '-' + j,
x : 51 * i,
y : 51 * j,
w : 50,
h : 50,
state : 'normal',
interactive : true,
colors : { normal : '#f00', hover : '#00f' },
events : {
onDraw : function(ctx){
ctx.fillStyle = this.colors[this.state];
ctx.fillRect(this.x,this.y,this.w,this.h);
this.setDims(this.x,this.y,this.w,this.h);
}
}
});
}
}
/* object that hold the information whether a certain object
* is in animation right now or not. This is used to prevent
* multiple Cmorph instances working on the same item
* */
var locked= {};
for(i= 0; i<6; i++)
for(j= 0; j<6; j++)
{
itemid = 'item-'+i+'-'+j;
itemid : false,
}
//then once I have done that
//animate all items with the function given below
function animate()
{
for(i=0;i<6;i++)
for(j=0;j<6;j++)
{
itemid = 'item-'+i+'-'+j;
if(locked.itemid)return; //guess even this will return errors!
locked.itemid = true;
var item = CANVAS.layers.get('myLayer').get(itemid);
new Cmorph(item,{
duration : 1000,
transition : 'bounce:out',
onComplete : function()
{
locked.itemid = false;
}
}
).morph({
y : (item.y == 50?375:50),
scale : (item.scale == 1?2:1)
});
}
}
CANVAS.addThread(new Thread({
id : 'myThread',
onExec : function(){
CANVAS.clear().draw();
}
}));
是我的语法正确,将所有的id被锁定或我会有错误。另外如果我犯了一个错误,请你纠正我。我知道这是一个非常愚蠢的怀疑,但请忍受我!谢谢:)
我将编辑我的问题以供进一步说明。 – Shouvik 2010-09-09 10:33:58
我根据您的更改调整了我的帖子。 – jwueller 2010-09-09 10:58:20
嘿谢谢!我想我将不得不等待有mootools经验的人来为我排序:) – Shouvik 2010-09-09 11:02:54