Skip to content

Instantly share code, notes, and snippets.

@since1976
Created February 21, 2012 20:42
Show Gist options
  • Save since1976/1878799 to your computer and use it in GitHub Desktop.
Save since1976/1878799 to your computer and use it in GitHub Desktop.
Show hide google map
$('a.toggle').click(function() {
event.preventDefault();
$("div.hide").slideToggle("fast");
var $t = $(this);
var href = $t.attr('href');
if(href == '#map') {
google.maps.event.addListener(map_canvas, 'resize', function() {
map_canvas.setCenter(map_bounds.getCenter());
});
google.maps.event.trigger(map_canvas, 'resize');
}
});
@objectivehtml
Copy link

Can you use the slideToggle() callback function?

var toggle = true;

$("div.hide").slideToggle("fast", function() {

    /* Only triggers on the first toggle */

    if(toggle) {
        google.maps.event.addListener(map_canvas, 'resize', function() {
            map_canvas.setCenter(map_bounds.getCenter());
        });

        google.maps.event.trigger(map_canvas, 'resize');
    }

    /* Resets the toggle */

    if(!toggle) {
        toggle = true;
    }
    else {
        toggle = false;
    }

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment