我想我只需要第二双眼睛,但由于某种原因,这两个动画被一个接一个地调用,导致无限循环,我似乎无法弄清楚为什么。第一个动画(tongueAnimation)应该运行6次并且仅交换地图标记图标图像,其中图像名称为hungry1,hungry2,hungry3 ...以对应于runcount变量。然后第二个动画(handAnimation)做同样的事情,但只在两个图像之间切换。我试图尽可能地评论代码。
var runcount = 2;
function tongueAnimation() {
//if animation has run six or less icon image swaps
if (runcount < 7) {
moveTongue();
}
else {
//runcount gets set to 1 for counting handAnimation which will now be called
runcount = 1;
handAnimation();
}
}
//sets the icon image for the marker
function moveTongue() {
//images are named hungry1, hungry2 ... so the count decides which image name will be used
orderMarker.icon = "images/hungry" + runcount + ".png";
//count that fact that moveTongue has been called
runcount++;
//call the function that invokeded this one
setTimeout(tongueAnimation(), 150);
}
function handAnimation() {
//if animation has run six or less icon image swaps
if (runcount < 7) {
moveHands();
}
//else reset runcount to original value of 2 and start over by calling tongueAnimation after three seconds
else {
runcount = 2;
setTimeout(tongueAnimation(), 3000);
}
}
function moveHands() {
if (orderMarker.icon != "images/hungryDown.png") {
orderMarker.icon = "images/hungryDown.png"
}
else {
orderMarker.icon = "images/hungry1.png"
}
runcount++;
setTimeout(handAnimation(), 250);
}