函数声明与函数表达式在间隔与循环中的表现
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();
$("#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();
相关文章推荐
- 函数声明、 函数表达式 与立即调用函数表达式的比较
- 函数声明和函数表达式的区别
- 函数声明和函数表达式
- Flash AS3.0三种间隔循环的表现方式
- 函数声明和函数表达式
- 深入理解,函数声明、函数表达式、匿名函数、立即执行函数、window.onload的区别.
- 函数声明和函数表达式
- 函数声明和函数表达式
- 函数声明与函数表达式
- 函数声明与函数表达式
- 关于函数表达式和函数声明
- 深入理解函数声明与函数表达式
- JavaScript的函数声明与函数表达式的区别
- 函数声明,函数表达式,块级作用域小结
- 函数声明和函数表达式的理解
- 函数声明与函数表达式
- PHP uniqid()函数可用于生成不重复的唯一标识符,该函数基于微秒级当前时间戳。在高并发或者间隔时长极短(如循环代码)的情况下,会出现大量重复数据。即使使用了第二个参数,也会重复,最好的方案是结
- 函数声明与函数表达式
- 函数声明与函数表达式
- 函数声明与函数表达式