代码:
<!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>
我不确定为什么当我点击按钮时Google Maps iframe没有覆盖整个屏幕。我已将iframe设置为background-size:cover;点击按钮后屏蔽整个屏幕。有人可以帮我弄这个吗?感谢。
答案 0 :(得分:0)
您需要在#map上添加高度以及更改iframe上的内联css。
#map
<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;
}
答案 1 :(得分:0)
乔丹回答说,
您需要允许#map
在屏幕上展开,然后将其提供
#map {
height: 100%;
width:100%; }
然后将iframe分散到#map
div,以便iframe代码为:width="100%" height="100%"
替换width="600" height="450"
。
另外,最后你可以移除#div
之外的空格,你可以在身体上添加零边距。
body { margin:0; }
答案 2 :(得分:0)
你只需要做三件事:
width:100%;
,height:100%;
和margin:0px;
。THEN
width:100%;
和height:100%
。和
min-width:100%
和min-height:100%
。以下是改变的问题:http://jsfiddle.net/65sf2f66/20/
以下是使用SO&#39的代码:
$(document).ready(function () {
$("#button").click(function () {
$("#map").fadeIn("slow");
});
});
&#13;
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%;}
&#13;
<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>
&#13;