您的位置:首页 > 其它

函数声明与函数表达式在间隔与循环中的表现

2015-05-11 18:34 316 查看
var run=function(){

$("#imagesbox div").each(function(index,val){

var width=Math.floor(Math.random()*10);

$(this).css('width',a[width]);

$(this).css('background-color',b[width]);

$("#imagesbox img").mousedown(function(e){

e.stopPropagation();

if(e.button==0){

console.log("left");

a.map(function(ele){

return ele-20;

})

}else if(e.button==2){

console.log("right");

a.map(function(ele){

return ele+20;

})

}

})

console.log(a[width]);

})

}

var time=setInterval(run,1000)

run();

以下方法:

var a=[200,210,220,230,240,250,260,270,280,190,180];

var b=["red","blue","yellow","#39f","gray","white","green"]

var time=setInterval('run()',1000)

var run=function(){

$("#imagesbox div").each(function(index,val){

var width=Math.floor(Math.random()*10);

$(this).css('width',a[width]);

$(this).css('background-color',b[width]);

$("#imagesbox img").mousedown(function(e){

e.stopPropagation();

if(e.button==0){

console.log("left");

a.map(function(ele){

return ele-20;

})

}else if(e.button==2){

console.log("right");

a.map(function(ele){

return ele+20;

})

}

})

console.log(a[width]);

})

}

run();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: