Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/02/2011, 20:47
racatan1
 
Fecha de Ingreso: febrero-2011
Mensajes: 7
Antigüedad: 13 años, 2 meses
Puntos: 0
Problema centrado mapa display none

Hola! Aprovecho para presentarme y dar las gracias a todo el mundo por este maravilloso oasis de ayuda. Tengo unos pocos conocimientos de html y css, y menos aún de jquery. Intento aprender este mundo procurando no morir en el intento. Os pido ayuda en este caso después de días dándole vueltas

Tengo un problema al mostrar un div que contiene un mapa de google maps. Al mostrar el div por defecto, que se abre con un slide, no hay problema. Pero quiero que al cargar la página esté oculto, para lo que uso "display: none;" en el div que lo alberga. Esto provoca que al abrirse el div, el mapa no aparece centrado (según he leído pq google maps interpreta el display none como div sin tamaño y coloca el centro del mapa en la esquina superior izquierda). Adjunto el código.

Sin embargo, en el último código que adjunto sí que se carga correctamente el mapa pero sin el efecto slide que busco (ni tampoco ocultándolo pulsando el mismo enlace).

¿Alguna solución para mostrar el mapa centrado con efecto slide partiendo de un div oculto? Muchísimas gracias.

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  4. <title>mostrar ocultar div</title>
  5. <script type="text/javascript" src="jquery-1.4.4.js"></script>
  6. <script type="text/javascript">
  7. $(function()
  8. {
  9.  
  10. $("#mostrar").click(function(event) {
  11. event.preventDefault();
  12. $("#caja").slideToggle(1000);
  13. });
  14.  
  15. $("#caja a").click(function(event) {
  16. event.preventDefault();
  17. $("#caja").slideUp();
  18. });
  19. });
  20. <style type="text/css">
  21. body {
  22.     font-family: Verdana, Arial, Helvetica, sans-serif;
  23.     font-size: 14px;
  24.     color: #FFFFFF;
  25. }
  26. a{
  27.     color:#000;
  28.     text-decoration:none;
  29. }
  30. #caja {
  31.     width:70%;
  32.     padding:5px;
  33.     display: none;
  34. }
  35. #mostrar{
  36.     display:block;
  37.     width:70%;
  38.     padding:5px;
  39. }
  40. </head>
  41. <a href="#" id="mostrar">MOSTRAR OCULTAR DIV</a>
  42.  
  43. <div id="caja">
  44. <iframe width="640" height="480" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.es/maps?f=q&amp;source=s_q&amp;hl=es&amp;geocode=&amp;q=Puerta+del+Sol,+Madrid&amp;aq=3&amp;sll=40.396764,-3.713379&amp;sspn=8.59894,19.753418&amp;ie=UTF8&amp;hq=&amp;hnear=Puerta+del+Sol,+PLAZA+Puerta+DEL+SOL,+14,+28013+Madrid,+Comunidad+de+Madrid&amp;ll=40.422906,-3.703423&amp;spn=0.031364,0.054932&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe>
  45. </div>
  46. </body>
  47. </html>


Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Documento sin título</title>
  5. function loadMap() {
  6. document.getElementById('map').innerHTML = '<iframe width="640" height="480" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.es/maps?f=q&amp;source=s_q&amp;hl=es&amp;geocode=&amp;q=Puerta+del+Sol,+Madrid&amp;aq=3&amp;sll=40.396764,-3.713379&amp;sspn=8.59894,19.753418&amp;ie=UTF8&amp;hq=&amp;hnear=Puerta+del+Sol,+PLAZA+Puerta+DEL+SOL,+14,+28013+Madrid,+Comunidad+de+Madrid&amp;ll=40.422906,-3.703423&amp;spn=0.031364,0.054932&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe>';
  7. }
  8. </head>
  9.  
  10.  
  11. <a href="#" id="mostrar" onclick="javascript:loadMap()">Ver mapa</a>
  12. <div id="map"></div>
  13. </body>
  14. </html>