这样使用,后面的4000无效
setTimeout(removeGift(customer_id,gift_id),4000);
function removeGift(customer_id,gift_id) {
var x = 100;
var y = 900;
var rand = parseInt(Math.random() * (x - y + 1) + y); // 随机的位置
$("#gift_"+customer_id+"_"+gift_id).animate({
bottom:900,
opacity:"0",
left: 1000,
},1000,'',function () {
$("#gift_"+customer_id+"_"+gift_id).remove();
});
}
这样使用,后面的4000秒有效
setTimeout(removeGift(customer_id,gift_id),4000);
function removeGift(customer_id,gift_id) {
return function(){
var x = 100;
var y = 900;
var rand = parseInt(Math.random() * (x - y + 1) + y); // 随机的位置
$("#gift_"+customer_id+"_"+gift_id).animate({
bottom:900,
opacity:"0",
left: 1000,
},1000,'',function () {
$("#gift_"+customer_id+"_"+gift_id).remove();
});
}
}
通过return function,就有效果。很奇怪!
本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6647469.html如需转载请自行联系原作者