2011-01-30 6 views
0

が動作しない.bind関数を理解するには、何か助けが必要です。 jqtouch Googleマップの例では、コードの残りの部分と同じページのdiv内に正しくマップを取得して表示します( )。良い!バインド機能のヘルプ?

$('#map').bind('pageAnimationEnd', function(event, info){ 
     if (info.direction == 'in') { 
      localiser(); 
     } 
    }); 

しかし、今Imはjqtouchと 負荷という別々のHTMLページにマップのdivを配置しようとしている:

地図のdivを結合するためのコードは次のようになります。 別のページがロードされていますが、マップに が表示されていません。 バインディングを変更する必要があります。多くの異なる のものを試しましたが、うまく動作しません。

私はあなたが代わり.bindの.live使用できることを読んで、.live は、DOMはすべてをコンパイルした後も動作していること、それは多分.live使用する 良いですか?

私はそれがどのように動作し、何を持っているのか理解してください。 別々のHTMLページを読み込むときにそれを動作させるにはどうすればいいですか? ありがとう!

答えて

0

の後にマップを初期化してバインドしてください。

+0

を使用しないため、あなたが間違っていることを知っていることを本当に願っています。 – Cronco

+0

@Croncoあなたは 'bind'の代わりに' delegate'を使うことを意味します。 – Raynos

+0

私はバインド、ライブ、デリゲートを試しましたが、何も動作しません。 –

0

ありがとうございます。しかし、私はあなたが言うようにそれを持っていると思う!そしてそれは私がそれを理解しない理由です。 これはgooglemap2.aspがどのように見えるかです:私はgooglemap2.aspで上記のdivを持っている場合は

<div id="map" class="notransform"> 
      <div class="toolbar"> 
       <h1>Map demo</h1> 
       <a href="#" class="back">Back</a> 
      </div> 

     <div id="map-container" class="notransform"> 
       <div id="map_text">This is my location</div> 

       <div id="map-overflow" style="overflow: hidden; padding: 0; border: 0;" class="notransform"> 
        <div id="map_canvas" style="margin-left: -20px; margin-top: -20px;" class="notransform"></div> 
       </div> 
     </div> 
</div> 

function localiser() { 
      if ($("#map_canvas").html()) return; 

      if ((window.orientation == (-90)) || (window.orientation == (90))) { 
       var width = 520; var height = 285; 
       $('#map_canvas').css("width",width+"px"); 
       $('#map_canvas').css("height",height+"px"); 
       $('#map-overflow').css("width",(width-40)+"px"); 
       $('#map-overflow').css("height",(height-10)+"px"); 
      } else { 
       var width = 360; var height = 435; 
       $('#map_canvas').css("width",width+"px"); 
       $('#map_canvas').css("height",height+"px"); 
       $('#map-overflow').css("width",(width-40)+"px"); 
       $('#map-overflow').css("height",(height-10)+"px"); 
      } 

      var myLatlng = new google.maps.LatLng(57.127426175, 12.26577967); 
      var myOptions = { 
       zoom: 16, 
       center: myLatlng, 
       disableDefaultUI: true, 
       mapTypeId: google.maps.MapTypeId.ROADMAP 
      } 
      var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions); 
      var image = new google.maps.MarkerImage("info.png",new google.maps.Size(32, 37)); 
      var shadowi = new google.maps.MarkerImage("shadow.png",new google.maps.Size(51, 37)); 
       var myLatLng = new google.maps.LatLng(57.127426175, 12.26577967); 
       var beachMarker = new google.maps.Marker({ 
        position: myLatLng, 
        map: map, 
         shadow: shadowi, 
        icon: image 
       }); 
     } 

jQT = new $.jQTouch({ 
     }); 

     $(document).ready(function(e){ 
      $(function(){ 
       $('body').bind('turn', function(event, info){ 
        var curr = $(".current").attr("id"); 
        switch (curr) { 
        case "map"  : 
         if (info.orientation == "landscape") { 
          var width = 520; var height = 285; 
          $('#map_canvas').css("width",width+"px"); 
          $('#map_canvas').css("height",height+"px"); 
          $('#map-overflow').css("width",(width-40)+"px"); 
          $('#map-overflow').css("height",(height-10)+"px"); 
         } else { 
          var width = 360; var height = 435; 
          $('#map_canvas').css("width",width+"px"); 
          $('#map_canvas').css("height",height+"px"); 
          $('#map-overflow').css("width",(width-40)+"px"); 
          $('#map-overflow').css("height",(height-10)+"px"); 
         } 
         break; 
        } 
       }); 
      }); 
      $('#map').live('pageAnimationEnd', function(event, info){ 
       if (info.direction == 'in') { 
        localiser(); 
       } 
      }); 
     }); 

そして、私はロード別々のページ(googlemap3.asp)はこのようになりますgooglemap3.aspの代わりにそれは動作します! 動的に生成されたコンテンツには `bind`の代わりに` live`を使用します:-)

+0

ページをロードした後に手動でイベントをトリガするとどうなるかを確認してください。 '.trigger'でイベントを手動でトリガーすることができます。 – Cronco

関連する問題