UPDATE2: Found the problem. I had * { width: 100%; height: 100% } at the top of my CSS file. This screwed up the entire map. Removing this solved the problem.
UPDATE: I was able to use CodePen to show my problem. Just click on the second box from the left in the navigation bar at the bottom.
http://codepen.io/anon/pen/CDeBc
If this question was asked already I apologise; I was unable to find one with this issue.
I've been working on this for a while, and can't figure out what the problem is. Here's an image of what happens (sorry, I'm not allowed to post images; just links):
http://i.imgur.com/cH8uvLT.png
I've got the "map-canvas" set to a div that is originally hidden that shows on a button click and animates from scale(0) to scale(1).
Things I've tried:
- Removing the popup animation.
- Using absolute values (ex. 100px) for width and height. I currently use percentages.
- Calling my initMap() function after the div has animated and after the page loads.
- Having display: block initially rather than display: none. Also tried display: hidden.
- Triggering the 'resize' event.
The only thing I've found to work is if I have the map on a separate HTML page, which isn't what I want. You should also know that when it initially loads, the map is correct for ~500ms, then the white "Map" box pops up.
Here is the CSS and HTML markup of the map container, and the jQuery for showing it:
HTML:
<div class="content popout" id="content_2"></div>
CSS:
.content {
width: 100%;
height: auto;
display: none;
text-shadow: none;
}
/* Map */
#content_2 {
background-color: red;
height: 100%;
}
/* Animation for "popping" out an element. Pops out from the middle of the screen. */
.popout {
animation-name: popout;
animation-duration: 500ms;
-webkit-animation-name: popout;
-webkit-animation-duration: 500ms;
}
@keyframes popout {
from { transform: scale(0); opacity: 0; }
to { transform: scale(1); opacity: 1; }
}
@-webkit-keyframes popout {
from { -webkit-transform: scale(0); opacity: 0; }
to { -webkit-transform: scale(1); opacity: 1; }
}
jQuery:
// inside some function
$("#content_"+(i + 1).toString()).show();
if (i + 1 == 2) // #content_2
initMap();
// end some function
function initMap() {
mapOptions = {
center: new google.maps.LatLng(42.9837, -81.2497),
zoom: 12,
};
map = new google.maps.Map(document.getElementById("content_2"), mapOptions);
}
Any help is appreciated. Thank you.
Cohen
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…