これはなぜ動作しないのですか?jQuery each with 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);
}
});
'$(" element ")。each()'の代わりに '$ .each'でsetTimeoutを試してみてください。 – Purag