1

添加后,我正在努力访问叠加层的内容。我添加了一个叠加层,其中包含一个具有特定类的 div。如果我稍后尝试使用 jQuery 修改此类的 CSS,则不会发生任何事情。

最终我想要做的是加载地图,然后将叠加层数组淡入其中,每个叠加层之间都有轻微的延迟 - 不是由点击或鼠标悬停触发,只是在加载地图之后。

我理想的代码是:

<script>
var twitmarkers = [];

$(function(){
$('#map').gmap3({ 
                action:'init',
                options:{
                  center:[55.944878,-3.187469],
                  zoom: 15,
                  mapTypeId: google.maps.MapTypeId.SATELLITE
                }
              },
              { 
                action: 'addMarker',
                latLng:[55.944878,-3.187469],
                data: "Remember When..?",
                options:{
                  icon:"icon_youarehere.png"
                }
              }
);

twitmarkers = document.getElementById("tw").getElementsByTagName("marker");
$.each(twitmarkers, function(i) {

var lat = val.getAttribute("lat");
var lng = val.getAttribute("lng");
var text = val.getAttribute("content");
var img = val.getAttribute("user");
var name =  val.getAttribute("name");

    $('#map').gmap3({
                      action:'addMarker',
                      latLng:[lat, lng],
                      options:{
                        icon: "icon_twit.png"
                      }
                    },
                    {
                      action:'addOverlay',
                      latLng:[lat, lng],
                      content:  '<div class="infoBox"><div class="tweet"><img src="' + img + '" /><h1>' + name + '</h1><p>' + text + '</p></div></div>',
                      offset: {
                        x:0,
                        y:0
                      }
                    }
    );

  });   

});
</script>
/*** other stuff ****/
<script>
  $('.infoBox').each(function (i) {
      $(this).delay(1000*i).fadeIn();
  });
</script>

我尝试在单独的函数中执行 addOverlay 并在 $.each 循环中使用 setTimeout 调用它,但根本没有加载任何内容。

我的 JavaScript 是否犯了一个荒谬的错误,或者完全遗漏了其他东西,或者它比我预期的要难做得多?

4

0 回答 0