1

The code:

<!DOCTYPE html>
<html>
<head>
<title>Google Maps</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<style type="text/css">
#button {
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
height: 50px;
width: 150px;
left: 50%;
top: 50%;
position: absolute;
margin-top: -25px;
margin-left: -75px;
border-radius: 5px;
color: white;
background-color: #4081FB;
font-size: 18px;
border: solid 1px #4081FB;
}
#button:hover {
cursor: pointer;
}
#map {
display: none;
position: absolute;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
$("#button").click(function () {
$("#map").fadeIn("slow");
});
});
</script>
</head>
<body>
<input type="button" id="button" value="Open Map" />
<div id="map">
<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m12!1m3!1d26496.05743213355!2d151.12773775!3d-33.88946895!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2sau!4v1439976442653" width="600" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>
</div>
</body>
</html>

I'm not sure why the Google Maps iframe is not covering the entire screen when i click on the button. I have set the iframe to background-size: cover; to cover up the whole screen once i have clicked on the button. Can someone help me with this? Thanks.

4

3 回答 3

0

你只需要做三件事:

  1. 为您的身体指定width:100%;,height:100%;和。margin:0px;

然后

  1. 为您的地图 div指定width:100%;and height:100%

  1. 删除 iframe 的内联宽度和高度,并为您的 iframe 指定min-width:100%and min-height:100%

这是一个带有更改的jsfiddle:http: //jsfiddle.net/65sf2f66/20/

这是使用 SO 代码段的代码:

$(document).ready(function () {
$("#button").click(function () {
$("#map").fadeIn("slow");
});
});
body  {
    width:100%;
    height:0%;
    margin:0px;
}
#button {
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
height: 50px;
width: 150px;
left: 50%;
top: 50%;
position: absolute;
margin-top: -25px;
margin-left: -75px;
border-radius: 5px;
color: white;
background-color: #4081FB;
font-size: 18px;
border: solid 1px #4081FB;
}
#button:hover {
cursor: pointer;
}
#map {
    height: 100%;
    width: 100%;
    display: none;
    position: absolute;
    background-size: cover;
    -webkit-background-size: cover;
    -moz-background-size: cover;
}
#map iframe {min-width:100%;min-height:100%;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="button" id="button" value="Open Map" />
<div id="map">
<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m12!1m3!1d26496.05743213355!2d151.12773775!3d-33.88946895!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2sau!4v1439976442653" frameborder="0" style="border:0" allowfullscreen></iframe>
</div>

于 2015-08-29T23:24:22.320 回答
0

您需要在#map 上添加高度以及更改 iframe 上的内联 css。

  • 添加高度/宽度(100vh,100vw)#map
  • 更改内联 html 属性的高度/宽度 (100%,100%)<iframe>

//HTML

<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m12!1m3!1d26496.05743213355!2d151.12773775!3d-33.88946895!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2sau!4v1439976442653" width="100%" height="100%" frameborder="0" style="border:0" allowfullscreen></iframe>

//CSS

#map {
    height: 100vh;
    width: 100vw;

    display: none;
    position: absolute;
    background-size: cover;
    -webkit-background-size: cover;
    -moz-background-size: cover;
}
于 2015-08-29T23:04:16.133 回答
0

正如乔丹所回答的,

你需要允许#map在屏幕上传播,所以给它

   #map {
    height: 100%;
    width:100%; }

然后使 iframe 跨#mapdiv 传播,因此 iframe 代码将是:width="100%" height="100%"替换width="600" height="450".

此外,最后您可以删除外部的空白,#div您可以在正文中添加零边距。

body { margin:0; }
于 2015-08-29T23:08:34.370 回答