Может ли кто-нибудь сказать мне, почему это не работает?jQuery каждый с SetTimeout
jeMarkers - это массив маркеров Google Maps.
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);
}
});
Попробуйте setTimeout в '$ .each' вместо' $ ("element"). each() '. – Purag