Ver Mensaje Individual
  #12 (permalink)  
Antiguo 22/11/2014, 14:45
javier_u
 
Fecha de Ingreso: noviembre-2014
Mensajes: 15
Antigüedad: 9 años, 5 meses
Puntos: 1
Respuesta: usar la misma funcion mas de 1 vez

Cita:
Iniciado por satanson123 Ver Mensaje
Hola mas arriba nuestro querido amigo Alexis88 tiene un ejemplo con 3 imagenes seguro que con ese ejemplo te funciona.
Gracias satanson. Lo he estado intentando pero el ejemplo de Alexis no lo sé aplicar. No sé nada de html mi de javascript.

Ésta es la solución de Alexis:

Código Javascript:
Ver original
  1. <img src = "imagen1.jpg" class = "foo" />
  2. <img src = "imagen2.jpg" class = "foo" />
  3. <img src = "imagen3.jpg" class = "foo" />
  4.  
  5. <button id = "bar">Cambiar tamaño de imágenes</button>


Código Javascript:
Ver original
  1. var boton = document.querySelector("#bar"),
  2.     imagenes = document.querySelectorAll(".foo"),
  3.     total = imagenes.length;
  4.  
  5. boton.addEventListener("click", function(){
  6.     for (var i = 0; i < total; i++){
  7.         if (getComputedStyle(imagenes[i]).maxWidth == "400px"){
  8.             imagenes[i].style.maxWidth = "120px";
  9.         }
  10.         else{
  11.             imagenes[i].style.maxWidth = "400px";
  12.         }
  13.     }
  14. }, false);


Le estoy dando vueltas pero no sé cómo escribir éste código para mi ejemplo:

Código Javascript:
Ver original
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <meta charset="utf-8">
  5.   <title>Ejemplo- FDW</title>
  6.  
  7. <script>
  8. function big_img(){
  9.       var img=document.getElementById('img-p');
  10.       if(img.style.maxWidth=="400px"){
  11.       img.style.maxWidth="120px";
  12.       }else{
  13.       img.style.maxWidth="400px";
  14.       }
  15.       }
  16. </script>
  17.  
  18. </head>
  19.  
  20. <body>
  21.   <div>
  22.     <button id = "bar" onclick="big_img(this)">Cambiar tamaño de imágenes</button>
  23.   </div>
  24.  
  25.     <img " id="img-p" src="http://www.absolut-canada.com/wp-content/uploads/2009/09/pesca-en-quebec.jpg" title="Click para ver">
  26.     <img " id="img-p" src="http://static3.absolutcaribe.com/wp-content/uploads/2009/09/playa-placencia.jpg" title="Click para ver">    
  27.  
  28. </body>
  29. </html>

Si alguien puede decirme se lo agradezco mucho. Un saludo.