javascript - 在点击叠加层时更改叠加层中图像的不透明度

标签 javascript html css google-maps-api-3

我在谷歌地图上有一个叠加层,该叠加层包含两个图像。当用户单击叠加层或叠加层内的图像顶部时,我想更改图像的不透明度。我尝试使用 domlistener,但它似乎不起作用。 这是代码,任何帮助都会很棒。

function initialize() {
 
  var myLatlng = new google.maps.LatLng(31.6167,65.7167);
  var mapProp = {
	zoom:9,
	center: myLatlng,
  	mapTypeId: google.maps.MapTypeId.TERRAIN,
    disableDefaultUI: true,
    scrollwheel: false,
    disableDoubleClickZoom: true,
    panControl: false, 
	scaleControl: false,
	touchmove: false

   
  };
  var map = new google.maps.Map(document.getElementById("map-canvas"),mapProp);
  map.overlayMapTypes.insertAt(0, new CoordMapType(new google.maps.Size(256, 256)));
  var swBound = new google.maps.LatLng(31.35,64.69);
  var neBound = new google.maps.LatLng(31.95,65.39);
  var bounds = new google.maps.LatLngBounds(swBound, neBound);
  var srcImg = 'Capture.png';
  var srcImg_2 = 'Lof1.png';
  overlay = new USGSOverlay(bounds, srcImg,srcImg_2, map);
 

	} 

function USGSOverlay(bounds, image, img, map) {

  this.bounds_ = bounds;
  this.image_ = image;
  this.map_ = map;
  this.img_ = img;
 
  this.div_ = null;
  this.setMap(map);
}
USGSOverlay.prototype.onAdd = function() {

  var div = document.createElement('div');
  div.style.borderStyle = 'none';
  div.style.borderWidth = '0px';
  div.style.position = 'absolute';

  var img = document.createElement('img');
  img.src = this.image_;
  img.style.width = '100%';
  img.style.height = '100%';
  img.style.position = 'absolute';
  img.className= 'lof_class';
  div.appendChild(img);
  var image = document.createElement('img');
  image.src = this.img_;
  image.style.width = '100%';
  image.style.height = '100%';
  image.style.position = 'absolute';
  image.className= 'lof_class';
  div.className= 'carousel';
  div.style.cursor= 'pointer';
  div.setAttribute("data-slide","1");
  div.appendChild(image);
 


  this.div_ = div;
  var panes = this.getPanes();
  panes.overlayLayer.appendChild(div);
   var me = this;
   google.maps.event.addDomListener(div, 'click', function() {
   image.style.opacity= '0.5';
  });

  
};

最佳答案

找到了,你必须使用 overlayMouseTarget 才能在叠加层上获得点击功能......

关于javascript - 在点击叠加层时更改叠加层中图像的不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32211608/

相关文章:

javascript - 改变事物的方向

html - iframe 内的 Accordion 跳转到父级的顶部

php - gmaps.js 循环遍历地址并添加标记

javascript - 如何获取在浏览器中呈现的二进制图像?

javascript - JQuery - 查找 Model[n].FieldName 并添加值

javascript - 将 html 标签作为 ejs 变量的值传递

javascript - 如何不连续但每 10 秒重复一次功能?

javascript - 如何在 Node.js 中同步使用请求?

html - 在linux终端通过google chrome/chromium下载网页

html - 如何使用 css/html 在句子中间使用图标/图像