2012-03-02 30 views

回答

4

以下是我創建解決統一淡出中風和填充一個解決方案,我做了很容易通過使其成爲一個功能重用。

秒是淡化出現和回調需要多長時間,因此您可以在完成後執行另一個操作。

在我的項目中,我的回調函數從地圖中刪除多邊形並刪除變量。

function polygon_fadeout(polygon, seconds, callback){ 
    var 
    fill = (polygon.fillOpacity*50)/(seconds*999), 
    stroke = (polygon.strokeOpacity*50)/(seconds*999), 
    fadeout = setInterval(function(){ 
     if(polygon.strokeOpacity + polygon.fillOpacity <= 0.0){ 
      clearInterval(fadeout); 
      polygon.setVisible(false); 
      if(typeof(callback) == 'function') 
       callback(); 
      return; 
     } 
     polygon.setOptions({ 
      'fillOpacity': Math.max(0, polygon.fillOpacity-fill), 
      'strokeOpacity': Math.max(0, polygon.strokeOpacity-stroke) 
     }); 
    }, 50); 
} 
2

使用Javascript setInterval()/clearInterval()遞增地改變多邊形的不透明度。事情是這樣的:

var opacity = [1, 0.8] 
var polygon = new google.maps.Polygon({ 
     strokeColor: "#000099", 
     strokeOpacity: opacity[0], 
     strokeWeight: 2, 
     fillColor: "#0000FF", 
     fillOpacity: opacity[1], 
     paths: [ /* your points here */ ] 
}); 

var interval = setInterval(function() { 
    if (opacity[0] <= 0.0 && opacity[1] <= 0.0) { 
    clearInterval(interval); 
    polygon.setVisible(false); 
    } else { 
    opacity[0] = Math.max(0.0, opacity[0] - 0.1); 
    opacity[1] = Math.max(0.0, opacity[1] - 0.1); 
    polygon.setOptions({strokeOpacity: opacity[0], fillOpacity: opacity[1]});  
    } 
}, 50); 
+0

該解決方案沒有解決均勻淡出中風和填充。在中風之前,我的填充物會消失很久。我投票了,因爲它是非常接近我的第一個解決方案。 – iambriansreed 2012-03-07 16:32:54