2010-12-10 67 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>"); 
      }