任何人都可以告訴我爲什麼這不起作用?jQuery每個與SetTimeout
jeMarkers是一組Google地圖標記。
function toggleBounce() {
var bcounter = 0;
$(jeMarkers).each(function() {
setTimeout(function() {
if (this.getAnimation() != null) {
this.setAnimation(null);
} else {
this.setAnimation(google.maps.Animation.BOUNCE);
}
}, bcounter * 100);
bcounter++;
});
}
如果我沒有setTimeout函數它的工作原理,但顯然同樣做的所有標記一次:
function toggleBounce() {
$.each(jeMarkers, function() {
if (this.getAnimation() != null) {
this.setAnimation(null);
} else {
this.setAnimation(google.maps.Animation.BOUNCE);
}
});
在'$ .each'而不是'$(「element」)。each()'中嘗試setTimeout。 – Purag 2011-12-23 10:21:05