2010-12-10 66 views
1

的代碼是:谷歌地圖V3信息窗口改變透明度與jQuery

function bindInfoWindow(marker, map, infoWindow, html) {       
     google.maps.event.addListener(marker, 'click', function() { 
     infoWindow.setContent("<div id='window'>" + html + "</div>"); 
    } 

var html = "<b>" + title + "</b> <br/><b>" + country; 

,我想,當國家爲英國或美國改變#window DIV或不透明度infoWindow

有沒有辦法可以用jQuery來做到這一點?

thnx

回答

0

你不需要jQuery來做到這一點。在你的CSS定義一個類與所需的透明度設置

.opacity { 
filter:alpha(opacity=50); //IE 

     opacity: 0.5; 

} 

修改你的函數傳遞一個國家作爲一個參數和類添加到根據期望的值

function bindInfoWindow(marker, map, infoWindow, html, country) {       
      google.maps.event.addListener(marker, 'click', function() { 
    opacityClass = (country=="UK" || country == "US") ? "opacity" : ""; 

infoWindow.setContent("<div id='window' class="+opacityClass+">" + html + "</div>"); 
     } 

,或者如果你的DIV想用jquery

 function bindInfoWindow(marker, map, infoWindow, html, country) {       
       google.maps.event.addListener(marker, 'click', function() { 
     if (country=="UK" || country == "US") { 
$("#window").addClass("opacity") 
} 

    infoWindow.setContent("<div id='window'>" + html + "</div>"); 
      }