day6
asked on
DIV Display:None Google Map Off Center
I've read about 30 different potential solutions online for this and have no idea which will be best to implement or even how to modify the Javascript to make it work.
http://www.restorationlutheran.com/
Click the DIRECTIONS link in the header. It pops open a google map, but the PIN for the location is off view in the upper left area and can't be seen unless you drag the map to find it.
The many posts online suggest that it is because of the CSS style display:none that the map can't properly align itself. I get that.
The suggested solutions vary from z-index trickery to visibility:hidden ideas, but I have no idea which will work with the code I found online to even make this div popup work in the first place.
The CSS:
The JS File:
The HTML:
So, I need to know how to get the map to be centered properly when it pops up.
http://www.restorationlutheran.com/
Click the DIRECTIONS link in the header. It pops open a google map, but the PIN for the location is off view in the upper left area and can't be seen unless you drag the map to find it.
The many posts online suggest that it is because of the CSS style display:none that the map can't properly align itself. I get that.
The suggested solutions vary from z-index trickery to visibility:hidden ideas, but I have no idea which will work with the code I found online to even make this div popup work in the first place.
The CSS:
/*GOOGLE MAP POPUP STYLES */
#blanket {
background-color:#111;
opacity: 0.65;
position:absolute;
z-index: 1111;
top:0px;
left:0px;
width:100%;
}
#popUpDiv {
position:absolute;
background-color:#eeeeee;
width:325px;
height:auto;
z-index: 1112;
top:10%;
left:40%;
padding:5px;
text-align:center;
}
The JS File:
function toggle(div_id) {
var el = document.getElementById(div_id);
if ( el.style.display == 'none' ) { el.style.display = 'block';}
else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar) {
if (typeof window.innerWidth != 'undefined') {
viewportheight = window.innerHeight;
} else {
viewportheight = document.documentElement.clientHeight;
}
if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
blanket_height = viewportheight;
} else {
if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
blanket_height = document.body.parentNode.clientHeight;
} else {
blanket_height = document.body.parentNode.scrollHeight;
}
}
var blanket = document.getElementById('blanket');
blanket.style.height = blanket_height + 'px';
var popUpDiv = document.getElementById(popUpDivVar);
popUpDiv_height=blanket_height/2-150;//150 is half popup's height
popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
if (typeof window.innerWidth != 'undefined') {
viewportwidth = window.innerHeight;
} else {
viewportwidth = document.documentElement.clientHeight;
}
if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
window_width = viewportwidth;
} else {
if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
window_width = document.body.parentNode.clientWidth;
} else {
window_width = document.body.parentNode.scrollWidth;
}
}
var popUpDiv = document.getElementById(popUpDivVar);
window_width=window_width/2-150;//150 is half popup's width
popUpDiv.style.left = window_width + 'px';
}
function popup(windowname) {
//blanket_size(windowname);
//window_pos(windowname);
toggle('blanket');
toggle(windowname);
}
The HTML:
<div id="blanket" style="display:none;"></div>
<div id="popUpDiv" style="display:none">
<a href="#" onclick="popup('popUpDiv')"><close></a><p>
<html>
<iframe width="300" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=500+East+Mitchell+Street,+Kendallville,+IN&hl=en&sll=37.0625,-95.677068&sspn=39.780156,59.0625&oq=500+e+mitchell+st+kendallvi&hnear=500+E+Mitchell+St,+Kendallville,+Indiana+46755&t=m&ie=UTF8&hq=&ll=41.444013,-85.259056&spn=0.019302,0.025749&z=14&iwloc=A&output=embed"></iframe><br /><small><a href="https://maps.google.com/maps?q=500+East+Mitchell+Street,+Kendallville,+IN&hl=en&sll=37.0625,-95.677068&sspn=39.780156,59.0625&oq=500+e+mitchell+st+kendallvi&hnear=500+E+Mitchell+St,+Kendallville,+Indiana+46755&t=m&ie=UTF8&hq=&ll=41.444013,-85.259056&spn=0.019302,0.025749&z=14&iwloc=A&source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small></html>
</div>
So, I need to know how to get the map to be centered properly when it pops up.
ASKER
Gary,
Um, sounds cool, but I'm not smart enough to even know how to experiment with this since I basically found the script online and put it on the site. I'm ok with CSS, but modifying the Javascript is what I am lost about.
Um, sounds cool, but I'm not smart enough to even know how to experiment with this since I basically found the script online and put it on the site. I'm ok with CSS, but modifying the Javascript is what I am lost about.
No guarantee on this but remove the display none of the element and amend like the following
<div id="popUpDiv" style="position:absolute;top:-999px;">
amend your onclick event from onclick="popup('popUpDiv')"
to onclick="document.getElementById('popUpDiv').setAttribute('style', 'position:static');popup('popUpDiv')"
ASKER
no go
Can you temporarily remove
<div id="blanket" style="display:none;"></di v>
Check it's working and centered - works from my side, haven't looked through your js closely but it seems your placing it in this wrapper at load? If so you don't need it doing this new way and you can just style the popup div as needed.
<div id="blanket" style="display:none;"></di
Check it's working and centered - works from my side, haven't looked through your js closely but it seems your placing it in this wrapper at load? If so you don't need it doing this new way and you can just style the popup div as needed.
That seems to be working fine now and in IE9 (it wasn't before)
ASKER
well i got it to center up next to the link, but now the CLOSE link inside the popup div doesn't work and there's a DIV overlay issue with the div contents below the popup bleeding through. I've set a z-index of 4000 to ensure that it is indeed on top of all other items, but I believe it isn't. I seem to recall something about the wrapper div (blanket) being there to prevent the bleed through or something.
I removed that div as you mentioned, but now it doesn't close and the bleed through is happening.
I removed that div as you mentioned, but now it doesn't close and the bleed through is happening.
Thats fine,
Change
to
and amend the following to target the blanket
Change
<div id="popUpDiv" style="position:absolute;top:-999px; margin-left:auto; margin-right:auto">
<a href="#" onclick="popup('popUpDiv')"><close></a><p>
<html>
<iframe width="300" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=500+East+Mitchell+Street,+Kendallville,+IN&hl=en&sll=37.0625,-95.677068&sspn=39.780156,59.0625&oq=500+e+mitchell+st+kendallvi&hnear=500+E+Mitchell+St,+Kendallville,+Indiana+46755&t=m&ie=UTF8&hq=&ll=41.444013,-85.259056&spn=0.019302,0.025749&z=14&iwloc=A&output=embed"></iframe><br /><small><a href="https://maps.google.com/maps?q=500+East+Mitchell+Street,+Kendallville,+IN&hl=en&sll=37.0625,-95.677068&sspn=39.780156,59.0625&oq=500+e+mitchell+st+kendallvi&hnear=500+E+Mitchell+St,+Kendallville,+Indiana+46755&t=m&ie=UTF8&hq=&ll=41.444013,-85.259056&spn=0.019302,0.025749&z=14&iwloc=A&source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small></html>
</div>
to
<DIV style="position:absolute;top:-999px; margin:0 auto" id="blanket">
<div id="popUpDiv">
<a href="#" onclick="popup('popUpDiv')"><close></a><p>
<html>
<iframe width="300" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=500+East+Mitchell+Street,+Kendallville,+IN&hl=en&sll=37.0625,-95.677068&sspn=39.780156,59.0625&oq=500+e+mitchell+st+kendallvi&hnear=500+E+Mitchell+St,+Kendallville,+Indiana+46755&t=m&ie=UTF8&hq=&ll=41.444013,-85.259056&spn=0.019302,0.025749&z=14&iwloc=A&output=embed"></iframe><br /><small><a href="https://maps.google.com/maps?q=500+East+Mitchell+Street,+Kendallville,+IN&hl=en&sll=37.0625,-95.677068&sspn=39.780156,59.0625&oq=500+e+mitchell+st+kendallvi&hnear=500+E+Mitchell+St,+Kendallville,+Indiana+46755&t=m&ie=UTF8&hq=&ll=41.444013,-85.259056&spn=0.019302,0.025749&z=14&iwloc=A&source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small></html>
</div></div>
and amend the following to target the blanket
onclick="document.getElementById('popUpDiv').setAttribute('style', 'position:static');popup('popUpDiv')"
becomesonclick="document.getElementById('blanket').setAttribute('style', 'position:static');popup('popUpDiv')"
Remove the opacity from the css for blanket and display:none
ASKER
now nothing displays at all
In popup.js remove
toggle('blanket');
toggle('blanket');
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
all changed, no popup displaying
Change popup('popUpDiv_show') to popUpDiv_show()
Change popup('popUpDiv_close') to popUpDiv_close()
Change popup('popUpDiv_close') to popUpDiv_close()
ASKER
ugh. it pops open now, but it's anchored to the left side of the screen and no matter what I do for the CSS to center it, it does nothing. I even added some more style attributes in the Javascript thinking it may center it, but nothing. It's also being overlayed by existing divs on the page.
function popUpDiv_show(){
document.getElementById('b lanket').s etAttribut e('style', 'position:static');
document.getElementById('b lanket').s etAttribut e('style', 'top:100px');
document.getElementById('b lanket').s etAttribut e('style', 'marginLeft:40%');
}
document.getElementById('b
document.getElementById('b
document.getElementById('b
}
ASKER
doesn't work. i tried like 5 combinations of what you did, and every one left it off screen completely. the only way it appears on screen is with just the two styles you had originally.
It's too late for me now, will get back to this tomorrow but I cannot see my amendment as above in popup.js
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Doh, in my defence it was very late for me...
ASKER
Great job Gary even though you were tired with the javascript thing. LOL.
Or change the order of events so the iframe has no source til you show it at which point in your js set the iframe source.
Just a couple of things I think might work.