谷歌标记的动画在地图加载与超时

2 javascript google-maps-api-3

我想在每个google marker的DROP动画上创建一个超时,但我认为标记和数组项的闭包代码是冲突的.我不太了解关闭,而且我对这个问题有点困惑.

我可以让他们一下子掉下来.

下降标记代码jsfiddle

但是我想在每个100毫秒的标记后超时.

这是我认为会起作用的

...

//Loop through nc array
for (var i = 0; i < nc.length; i++) {

   //Create 100 ms rule on marker creation
   setTimeout(function () {

     //Create marker
     var marker = new google.maps.Marker({
       position: nc[i],
       map: map,
       title: "tron" + i,
       animation: google.maps.Animation.DROP,
     });

    }, i * 100);

   //Creating the closure
   (function (i, marker) {

     //Add infowindow
     google.maps.event.addListener(marker, 'click', function () {
         if (!infowindow) {
            infowindow = new google.maps.InfoWindow();
         }
         //Setting content of info window
         infowindow.setContent('<h2>Tron lives | ' + i + '</h2>');
             infowindow.open(map, marker);
         });
      })(i, marker);
    };

...
Run Code Online (Sandbox Code Playgroud)

但这不起作用.我想,一旦在循环中创建了标记,就会在该创建过程中设置超时,这将产生降雨标记效果.

Kyl*_*ham 6

和@Bryan Weaver有同样的想法.拿起你的小提琴并稍微修改它以在函数中创建标记,并迭代地设置超时.结束以下内容,它成功地完成了"下雨"效果.

    var addmarker = function(i) {
        //Create marker
            var marker = new google.maps.Marker({
                position: nc[i],
                map: map,
                title: "tron" + i,
                animation: google.maps.Animation.DROP,
            });

            //Creating the closure
            (function (i, marker) {   

                //Add infowindow
                google.maps.event.addListener(marker, 'click', function () {
                    if (!infowindow) {
                        infowindow = new google.maps.InfoWindow();
                    }
                    //Setting content of info window
                    infowindow.setContent('<h2>Tron lives | ' + i + '</h2>');

                    infowindow.open(map, marker);
                });
            })(i, marker); 
        if(i++ < nc.length) {
            setTimeout(function() {addmarker(i)}, 100);
        }

    }
    addmarker(0);             
Run Code Online (Sandbox Code Playgroud)

这是完整的小提琴:http: //jsfiddle.net/LzJ8B/