Foros del Web » Programando para Internet » Javascript »

Intercambio de imagenes

Estas en el tema de Intercambio de imagenes en el foro de Javascript en Foros del Web. Buenas tardes, chicos me dan una mano por fa Tengo el siguiente codigo, el cual muestra en la capa1 una imagen en tamaño 500 x ...
  #1 (permalink)  
Antiguo 13/09/2013, 15:17
 
Fecha de Ingreso: noviembre-2010
Mensajes: 204
Antigüedad: 13 años, 5 meses
Puntos: 1
Intercambio de imagenes

Buenas tardes, chicos me dan una mano por fa

Tengo el siguiente codigo, el cual muestra en la capa1 una imagen en tamaño 500 x 500. En la capa2 tengo 5 imagenes en tamaño 15 x 15.

¿Como hago para que cuando el usuario haga docle click en una imagen de la capa2 esta se vea en la capa1?
Código HTML:
Ver original
  1.  
  2. <title>Catalogo</title>
  3. </head>
  4.  
  5.  
  6. <div id="capa1" align="center">
  7. <img src="http://econscientes.com/images/imagen-1.jpg" width="500" height="500">
  8. </div>
  9.  
  10. <div id="capa2" align="center">
  11. <img src="http://econscientes.com/images/imagen-1.jpg" width="15" height="15">
  12. <img src="http://econscientes.com/images/imagen-2.jpg" width="15" height="15">
  13. <img src="http://econscientes.com/images/imagen-3.jpg" width="15" height="15">
  14. <img src="http://econscientes.com/images/imagen-4.jpg" width="15" height="15">
  15. <img src="http://econscientes.com/images/imagen-5.jpg" width="15" height="15">
  16. </div>
  17.  
  18. </body>
  19.  
  20. </html>

Gracias
  #2 (permalink)  
Antiguo 13/09/2013, 15:47
Colaborador
 
Fecha de Ingreso: mayo-2008
Ubicación: $MX['VZ']['Xalapa']
Mensajes: 3.005
Antigüedad: 16 años
Puntos: 528
Respuesta: Intercambio de imagenes

Si lo que quieres es hacer que una imagen pase de un div a otro tienes que

asignar el evento ondblclick="" a cada imagen
cuando se de el evento, agregar el nodo (elemento) al div destino
eliminar el elemento "clickeado"
  #3 (permalink)  
Antiguo 13/09/2013, 17:13
 
Fecha de Ingreso: noviembre-2010
Mensajes: 204
Antigüedad: 13 años, 5 meses
Puntos: 1
Respuesta: Intercambio de imagenes

ocp001a, gracias por tu colaboracion

Lo de doble click es un decir, realmente con un click es suficiente.

A cada imagen le coloque el evento onclick() y cree una funcion denominada ver_imagen, pero no se como referenciar cada imagen, en esta parte me pierdo.
Código HTML:
Ver original
  1.  
  2. <title>Catalogo</title>
  3.  
  4. <script language="javascript">
  5.  
  6. function ver_imagen(){
  7.  document.getElementByID('capa1');
  8. }
  9.  
  10.  
  11. </head>
  12.  
  13.  
  14. <div id="capa1" align="center">
  15. <img src="http://econscientes.com/images/imagen-1.jpg" width="500" height="500">
  16. </div>
  17.  
  18. <div id="capa2" align="center">
  19. <img src="http://econscientes.com/images/imagen-1.jpg" width="15" height="15" onclick="ver_imagen()">
  20. <img src="http://econscientes.com/images/imagen-2.jpg" width="15" height="15" onclick="ver_imagen()">
  21. <img src="http://econscientes.com/images/imagen-3.jpg" width="15" height="15" onclick="ver_imagen()">
  22. <img src="http://econscientes.com/images/imagen-4.jpg" width="15" height="15" onclick="ver_imagen()">
  23. <img src="http://econscientes.com/images/imagen-5.jpg" width="15" height="15" onclick="ver_imagen()">
  24. </div>
  25.  
  26. </body>
  27.  
  28. </html>
  #4 (permalink)  
Antiguo 13/09/2013, 17:35
Colaborador
 
Fecha de Ingreso: mayo-2008
Ubicación: $MX['VZ']['Xalapa']
Mensajes: 3.005
Antigüedad: 16 años
Puntos: 528
Respuesta: Intercambio de imagenes

Aquí
onclick="ver_imagen()"

puedes pasar el elemento dierctamente

onclick="ver_imagen(this)"

o bien su id

onclick="ver_imagen(this.id)"

No estoy seguro de qué quieres lograr, pero a partir de aquí podrías hacer las demás operaciones de agregar un nodo a un div y quitarlo del otro.
  #5 (permalink)  
Antiguo 13/09/2013, 19:10
 
Fecha de Ingreso: noviembre-2010
Mensajes: 204
Antigüedad: 13 años, 5 meses
Puntos: 1
Respuesta: Intercambio de imagenes

ocp001a, lo organice de esta forma, pero no logro que me funcione

¿Que Me falta?

Código HTML:
Ver original
  1.  
  2. <title>Catalogo</title>
  3.  
  4. <script language="javascript">
  5.  
  6. function ver_imagen(){
  7.  document.getElementByID('capa1').src = img.src;
  8. }
  9.  
  10.  
  11. </head>
  12.  
  13.  
  14. <div id="capa1" align="center">
  15. <img src="http://econscientes.com/images/imagen-1.jpg" width="500" height="500">
  16. </div>
  17.  
  18. <div id="capa2" align="center">
  19. <img src="http://econscientes.com/images/imagen-1.jpg" width="15" height="15" onclick="ver_imagen(this)">
  20. <img src="http://econscientes.com/images/imagen-2.jpg" width="15" height="15" onclick="ver_imagen(this)">
  21. <img src="http://econscientes.com/images/imagen-3.jpg" width="15" height="15" onclick="ver_imagen(this)">
  22. <img src="http://econscientes.com/images/imagen-4.jpg" width="15" height="15" onclick="ver_imagen(this)">
  23. <img src="http://econscientes.com/images/imagen-5.jpg" width="15" height="15" onclick="ver_imagen(this)">
  24. </div>
  25.  
  26. </body>
  27.  
  28. </html>

Última edición por isabelramirezmontoya; 13/09/2013 a las 19:26
  #6 (permalink)  
Antiguo 13/09/2013, 19:51
 
Fecha de Ingreso: enero-2012
Ubicación: <?php echo"Los teques"; ?>/////estado miranda
Mensajes: 196
Antigüedad: 12 años, 3 meses
Puntos: 9
Respuesta: Intercambio de imagenes

Código HTML:
Ver original
  1.  
  2. <title>Catalogo</title>
  3.  
  4. <script language="javascript">
  5.  
  6. function ver_imagen(src){
  7. document.getElementById("img1").src = src;
  8. }
  9.  
  10.  
  11. </head>
  12.  
  13.  
  14. <div id="capa1" align="center">
  15. <img id="img1" src="http://econscientes.com/images/imagen-1.jpg" width="500" height="500">
  16. </div>
  17.  
  18. <div id="capa2" align="center">
  19. <img src="http://econscientes.com/images/imagen-1.jpg" width="15" height="15" onclick="ver_imagen(this.src)">
  20. <img src="http://econscientes.com/images/imagen-2.jpg" width="15" height="15" onclick="ver_imagen(this.src)">
  21. <img src="http://econscientes.com/images/imagen-3.jpg" width="15" height="15" onclick="ver_imagen(this.src)">
  22. <img src="http://econscientes.com/images/imagen-4.jpg" width="15" height="15" onclick="ver_imagen(this.src)">
  23. <img src="http://econscientes.com/images/imagen-5.jpg" width="15" height="15" onclick="ver_imagen(this.src)">
  24. </div>
  25.  
  26. </body>
  27.  
  28. </html>

Listado de errores:
1.- primero que nada al pasar la linea
Código Javascript:
Ver original
  1. onclick="ver_imagen(this);"
No estas diciendo si es el SRC o el id :P

2.- en la funcion le estas definiendo el SRC a la capa 1, y la capa 1 es un div, yo le puse id a la imagen, y le di el SRC a ella

3.-al definir la variable ver_imagen en javascript, no estas recogiendo los valore.

Si quieres ponerlo con doble click, cambia los "Onclick" por "Ondblclick"

Etiquetas: html, imagenes, intercambio
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:24.