我可以等待或检查具有值的变量才能继续功能吗?
var someVar = false;
$('.someEl').animate({'marginLeft': 100}, 500, function () {
// animating complete
someVar = true;
});
function someFunction () {
// watch someVar to be true and then run the code in this function
}
someFunction();
答案 0 :(得分:1)
直接前进:
var someVar = false;
$('.someEl').animate({'marginLeft': 100}, 500, function () {
// animating complete
someVar = true;
someFunction();
});
function someFunction () {
// watch someVar to be true and then run the code in this function
}
有一种手表:
var someVar = false;
$('.someEl').animate({'marginLeft': 100}, 500, function () {
// animating complete
someVar = true;
});
function someFunction () {
if (someVar) { do.. }
else setTimeout(function() { someFunction(); }, 1);
}