且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

动画后,Google地图容器无法正确调整大小

更新时间:2023-02-05 22:28:47

ha,因为您在之前触发调整大小事件 动画甚至开始:-)您必须等到它结束。为此,请使用 .animate的第四个参数 - 完成回调这是在动画结束后调用的:

Ha ha because you trigger the resize event before the animation even starts :-) You have to wait until it ends. For this, use the 4th argument of .animate - the complete callback which is called after the animation ends:

$('#add').click(function() {
     $("#container-map").animate({
        height: '50%',
        minHeight: '50%'
     }, 1500, function () {
          google.maps.event.trigger(map, 'resize');
     });
});