gpt4 book ai didi

javascript - 无法加载我的谷歌地图小部件。它工作得很好,直到我决定将其隐藏(使用 .hide)

转载 作者:行者123 更新时间:2023-11-28 00:09:25 25 4
gpt4 key购买 nike

我的谷歌地图小部件工作得很好,直到我决定将其隐藏(使用 .hide jquery )。您可以单击 div 以显示小部件(使用 .toggle jquery)。但是现在, map 不会加载到容器内。就好像它认为它仍然隐藏着一样。有任何想法吗?如果我单击浏览器上的另一个选项卡,然后直接返回页面,则会加载 map 。

           <!DOCTYPE html>
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js"></script>
<link href='http://fonts.googleapis.com/css?family=Lato:400,700' rel='stylesheet' type='text/css'>
<title></title>
<link rel="stylesheet" href="sss/sss.css" type="text/css" media="all">
<script src="includes/jquery-1.9.1.min.js"></script>
<script src="sss/sss.min.js"></script>
<script src="includes/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
$("#slidemenu ul").hover(function(){
$(".item").toggle("slide", { direction: "right" }, 400 );
});
});

$(document).ready(function(){
$(".menubutton").mouseover(function(){
$('.menubutton #line').css( "background-color", "orange")
})
.mouseout(function() {
$('.menubutton #line').css( "background-color", "white")
});
});

$(document).ready(function(){
$(".item").mouseover(function(){
$('.menubutton #line').css( "background-color", "orange")
})
.mouseout(function() {
$('.menubutton #line').css( "background-color", "white")
});
});

$(document).ready(function(){
$(".oneitem").mouseover(function(){
$('.menubutton #line').css( "background-color", "orange")
})
.mouseout(function() {
$('.menubutton #line').css( "background-color", "white")
});
});


</script>
<script>
function initialize() {
var mapProp = {
center:new google.maps.LatLng(54.149517, -8.278809),
zoom:13,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("fermoy"),mapProp);
var point = new google.maps.LatLng(54.149517, -8.278809);
var marker = new google.maps.Marker({
position: point,
title:"Fermoy"
});

// To add the marker to the map, call setMap();
marker.setMap(map);

}
google.maps.event.addDomListener(window, 'load', initialize);

</script>
<script>
function initialize() {
var mapProp = {
center:new google.maps.LatLng(54.149517, -8.278809),
zoom:13,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("map1"),mapProp);
var point = new google.maps.LatLng(54.149517, -8.278809);
var marker = new google.maps.Marker({
position: point,
title:"Map"
});

// To add the marker to the map, call setMap();
marker.setMap(map);



}
google.maps.event.addDomListener(window, 'load', initialize);

</script>
<script>

function initialize() {
var mapProp = {
center: new google.maps.LatLng(56.104607, -6.698879),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map2"), mapProp);
var point = new google.maps.LatLng(56.104607, -5.698879);
var marker = new google.maps.Marker({
position: point,
title: "Map"
});



}
google.maps.event.addDomListener(window, 'load', initialize);



</script>
<script>
function initialize() {
var mapProp = {
center:new google.maps.LatLng(53.344573,-6.370321),
zoom:13,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("map3"),mapProp);
var point = new google.maps.LatLng(53.344573,-6.370321);
var marker = new google.maps.Marker({
position: point,
title:"map"
});

// To add the marker to the map, call setMap();
marker.setMap(map);

}
google.maps.event.addDomListener(window, 'load', initialize);

</script>




<script type="text/javascript">
function diffImage(img)
{
if(img.src.match(/up/)) img.src = "images/down.png";
else img.src = "images/up.png";
}
</script>
<script>
$(document).ready(function(){
$(".toshow").hide();
});


$(document).ready(function(){
$("#button").click(function(){
$(".toshow").toggle();
});
});
</script>





<style>
/* Standard Menu */
body {
margin: 0px;
padding: 0px;

}
header {
background-color: black;
height: 60px;
width: 100%;
position: fixed;
z-index: 100;
} /* This is our finished menu */
.blackbar {
height: 60px;
width: 100%;
background-color: black;
} /* As the menu is not fixed this keeps a black bar behind when the menu is at the veru top */
.logo img {
height: 40px;
background-color:black;
float: left;
margin-top: 0px;
padding:9px;
margin-left: 30px;
} /* The McMahons Logo */
#navdiv li {
display: inline-block;
vertical-align: middle;
}
#navdiv a {
text-decoration: none;
color: white;
text-transform: uppercase;
font-family: 'Lato', sans-serif;
}
#navdiv a:active {
color:orange;
} /* Current Page Link Highlighted Orange */
#navdiv a:hover {
color: orange;
} /* Link Hovered Orange */
nav {
width: auto;
float: right;
word-spacing: 30px;
height: 60px;
min-width: 600px;
} /* This is the part of the menu with the page links laid out horizontally */
ul {
width: 600px;
letter-spacing: 0.14em;
margin-right: 20px;
margin-left: 20px;
padding-left: 0px;
} /* List of Links to Pages */
/* Slider Menu */
#slidemenu { /* The Slide In Menu */
height: 40px;
width: 105px;
padding: 0px;
margin: 0px;
float: right;
margin-right: 30px;
}
#slidemenu a {
text-decoration: none;
color: white;
font-family: 'Lato', sans-serif;
}
#slidemenu ul {
list-style-type: none;
margin: 0px;
padding: 0px;
}
#slidemenu ul .item {
display: none;
right: 70px;
} /* Current slidemenu position */
.oneitem {
display: block;
background-color: black;
width: 100px;
height: 19px;
text-align: center;
padding: 19px;
} /* This is already in place, jQuery doesnt need to bring this in */
.item {
display: block;
z-index: 100;
background-color: black;
width: 100px;
height: 20px;
text-align: center;
padding: 19px;
} /* jQuery brings this into play, by default it is overtaken by (#menubutton ul .item) as this is more specific */
/* MENU BUTTON */
.menubutton {
background-color: black;
visibility: visible;
margin-top: 10px;
margin-right: 20px;
background-color: black;
position: absolute;
right: 20px;
}
#line {
background-color: white;
width: 40px;
height: 5px;
margin: 6px;
}
/* RESIZING WINDOW ADJUSTMENTS */
@media only screen and (max-width: 950px) {
nav{
display: none;
}
} /* Rids Navgation Links when screen is minimized */
@media only screen and (min-width: 950px) {
#slidemenu{
display: none;
}
} /* Rids Menu Button when at full-screen */
@media only screen and (max-width: 450px) {
.logo img{
margin-left: 4px;
}
} /* Pulls Logo slightly left when screen is highly minimized to prevent Menu Bottom Colliding */
html, body, #container { height: 100%; }
body > #container { height: auto; min-height: 100%; }
#footer {
clear: both;
position: relative;
z-index: 10;
height: 130px;
margin-top: 3em;
background-color: black;
bottom: 0px;
overflow: hidden;

}
#content { padding-bottom: 3em; }
.box{
width: 15%;
height:124px;
display: inline-block;
min-width: 200px;
}
.box h1{
font-family: 'Lato', sans-serif;
font-size: 20px;
}
#social img{
width: 60px;
height:60px;
margin:0px;
padding-bottom: 10px;
}
#social h1{
margin-bottom: 5px;
padding-left: 53px;
}
.trusshead h1{
font-family: 'Lato', sans-serif;
font-size: 60px;
text-transform: uppercase;
margin:0px;



}
#fermoy{
margin-top: 30px;
border: 2px solid black;

}


#fermoy2, #blanch, #ballyfermott, #portarlington, #limerick, #cork, #dunmanway, #tralee, #galway, #waterford, #coleraine, #derry, #omagh {
margin-top: 30px;
border: 2px solid black;
border-top: 3px solid black;
}



.text p {
font-family: 'Lato', sans-serif;
text-align: center;

}
.contactboxes {
float: left;
width: 195px;
height: 308px;

}
.contactboxes h3{
font-family: 'Lato', sans-serif;
margin: 0px;
margin-top: 35px;

}
.contactboxes p{
font-family: 'Lato', sans-serif;
margin: 0px;

}


</style>
</head>
<body>
<header>
<div class="logo">
<img src="images/mclogo.png">
</div>
<div id="navdiv">
<div id="slidemenu">
<ul>
<li class="menubutton">
<div id="line"></div>
<div id="line"></div>
<div id="line"></div>
</li>
<li class="oneitem" style="padding-bottom: 22px;"></li>
<li class="item" ><a href="index.html">Home</a></li>
<li class="item"><a href="products.html">Products</a></li>
<li class="item"><a href="services.html">Services</a></li>
<li class="item"><a href="blog.html">Blog</a></li>
<li class="item"><a href="contact.html">Contact</a></li>
</ul>
</div>
<nav>
<ul>
<li class="hide active"><a href='index.html'>Home</a></li>
<li class="hide"><a href='products.html'>Products</a></li>
<li class="hide"><a href='services.html'>Services</a></li>
<li class="hide"><a href='blog.html'>Blog</a></li>
<li class="hide"><a href='contact.html'>Contact</a></li>
<li class="hide">
<a class="fb_icon" href="https://www.facebook.com/mcmahons123?fref=ts" target="_blank">
<img src='images/facebook.png' onmouseover="this.src='images/facebookorange.png';" onmouseout="this.src='images/facebook.png';"/></a>
</li>
</ul>
</nav>
</div>
</header>
<div id="container">
<div style="background-color: black; width:100%; height:60px; visibility: hidden;"></div>
<div id="content">

<div style="width: 1150px;; margin: 0 auto; height: 30px; margin-top: 20px;">
<div style="float:right; "><h2 style="font-family: 'Lato', sans-serif; margin:0px;">Email: &nbsp@hotmail</h2></div>
<div style="float: left;"><h2 style="font-family: 'Lato', sans-serif;margin:0px; ">Call: &nbsp12344</h2></div>
</div>
<div style="width: 100%; margin-top: 0px;">
<div style="width: 40px; height: 4px; background-color: black; margin: 0 auto;"></div>
</div>
<div class="trusshead" style="margin: 0 auto; width: 190px;">
<h1>Stack</h1>
</div>
<div style="width: 100%; margin-top: 1px;">
<div style="width: 40px; height: 4px; background-color: black; margin: 0 auto;"></div>
</div>
<div class="text" style="width: 520px; margin: 0 auto; margin-top: 50px;">
<p>123 Testing 123</p>
</div>

<div style="margin:0 auto; width: 780px; height: 400px; margin-top: 50px;">
<div class="contactboxes">
<h3>Plant</h3>
<div style="margin-top: 10px;">
<p style="margin-bottom: 10px"> 123<br>Happy Rd,<br>RedHill,<br>Spain</p>
<p style="margin-bottom:5px;"> <strong>Email:</strong><br> @google</p>
<p style="margin-bottom:5px;"> <strong>Tel:</strong> <br>000000</p>
<p> <strong>Fax:</strong> <br>00000</p>
</div>
</div>
<div id="map1" style="width:405px; height:308px; float:right; display:inline; "></div>
</div>

<div style="width: 430px; height: 30px; margin:0 auto;"><p style="font-family: 'Lato', sans-serif">Click the arrow to expand a list of maps.
</p></div>
<div id="button" style="width: 30px; margin:0 auto;">
<img src="images/down.png" id="image1" style="height: 30px;" onclick=diffImage(this) /></div>
<div class="toshow">
<div style="width: 90px; margin: 0 auto;"><h2 style="font-family: 'Lato', sans-serif; ">Maps</h2></div>

<div style="margin:0 auto; width: 780px; height: 1030px; ">

<div style="width:100%; height: 405px;">
<div class="contactboxes">
<h3>Dub</h3>
<div style="margin-top: 10px;">
<p style="margin-bottom: 10px"> 123<br>Happy Rd,<br>RedHill,<br>Spain</p>
<p style="margin-bottom:5px;"> <strong>Email:</strong><br> @google</p>
<p style="margin-bottom:5px;"> <strong>Tel:</strong> <br>000000</p>
<p> <strong>Fax:</strong> <br>00000</p>
</div>
</div>
<div id="map2" style="width:405px; height:308px; float:right; display:inline; "></div>
</div>

<div style="width:100%; height: 405px;">
<div class="contactboxes">
<h3>Dub</h3>
<div style="margin-top: 10px;">
<p style="margin-bottom: 10px"> 123<br>Happy Rd,<br>RedHill,<br>Spain</p>
<p style="margin-bottom:5px;"> <strong>Email:</strong><br> @google</p>
<p style="margin-bottom:5px;"> <strong>Tel:</strong> <br>000000</p>
<p> <strong>Fax:</strong> <br>00000</p>
</div>
</div>
<div id="map3" style="width:405px; height:308px; float:right; display:inline; "></div></div>


</div>





</div>
</div>

<div id="footer">
<div style="margin: 0 auto; width: 705px;"> <!--To Centre Boxes-->
<div class="box"> <!--Box-->
<h1 style="color: white; padding-top:40px; margin-left: 40px;">News</h1>
<img src="images/black.jpg" style="width: 190px; height: 35px; "> <!--Black Box under writing - keeps writing off bottom-->
</div>
<div style="width: 40px; display: inline-block;"></div> <!--Space Div-->
<div class="box" id="social"> <!--Box-->
<h1 style="color: white;">Follow Us</h1>
<div style="width: 90px; height: 2px; background-color: white; margin-bottom: 5px; margin-left: 51px"></div> <!--Line-->
<div style="width: 128px; margin-left: 33px;"> <!-- Containing div for two circles-->
<a href="https://www.facebook.com"><img src="images/facebookfooter.png"></a>
<img src="images/twitterfooter.png">
</div>
</div>
<div style="width: 40px; display: inline-block"></div> <!--Space Div-->
<div class="box"> <!--Box-->
<img src="images/ce.png" style="height: 30px; margin-left: 75px; ">
<img src="images/black.jpg" style="width: 190px; height: 40px; "> <!--Black Box under writing - keeps writing off bottom-->
</div>
</div>
</div>
</body>
</html>

最佳答案

这里有几件事。

其中之一是您的 div id 是 maps但是你的getElementByIdmap

第二个是谷歌地图试图计算出容器 div 的高度和宽度,但它无法做到这一点。您应该为您的 div 指定明确的高度和宽度,例如: <div id="map" style="height:500px;width:500px"></div>

第三个是当您取消隐藏需要通过 google.maps.event.trigger(map, "resize"); 通知 map 的 div 时,会发生调整大小。

通过这些更改,您的代码应该按预期工作。我在 https://jsfiddle.net/tjvr5uaq/1/ 创建了一个 jsfiddle来演示。

关于javascript - 无法加载我的谷歌地图小部件。它工作得很好,直到我决定将其隐藏(使用 .hide),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31038873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com