2011-04-07 13 views
6

Este código funcionaba bien hasta que fui a Firefox 4 y ahora se requieren dos clics en la misma imagen para que el cambio de tamaño funcione. ¿Alguna idea? Aquí está el código.jQuery en Firefox 4

$(document).ready(function(){ 

$("#slideShow a").click(function() { 
var imgTitle = $(this).children('img').attr('title'); // Find the image title 
$("#thecap").html(' ' + imgTitle + ' '); 
$("#lgImage").attr('src', $(this).children('img').attr('rel')); 
$(".resizeme1").aeImageResize({ height: 372 }); 
}); 

}); 

Aquí está el código del complemento en caso de que alguien vea algo en él.

(function($) { 



    $.fn.aeImageResize = function(params) { 

    var aspectRatio = 0 
     // Nasty I know but it's done only once, so not too bad I guess 
     // Alternate suggestions welcome :) 
     , isIE6 = $.browser.msie && (6 == ~~ $.browser.version) 
     ; 

    // We cannot do much unless we have one of these 
    if (!params.height && !params.width) { 
     return this; 
    } 

    // Calculate aspect ratio now, if possible 
    if (params.height && params.width) { 
     aspectRatio = params.width/params.height; 
    } 

    // Attach handler to load 
    // Handler is executed just once per element 
    // Load event required for Webkit browsers 
    return this.one("load", function() { 

     // Remove all attributes and CSS rules 
     this.removeAttribute("height"); 
     this.removeAttribute("width"); 
     this.style.height = this.style.width = ""; 

     var imgHeight = this.height 
     , imgWidth = this.width 
     , imgAspectRatio = imgWidth/imgHeight 
     , bxHeight = params.height 
     , bxWidth = params.width 
     , bxAspectRatio = aspectRatio; 

     // Work the magic! 
     // If one parameter is missing, we just force calculate it 
     if (!bxAspectRatio) { 
     if (bxHeight) { 
      bxAspectRatio = imgAspectRatio + 1; 
     } else { 
      bxAspectRatio = imgAspectRatio - 1; 
     } 
     } 

     // Only resize the images that need resizing 
     if ((bxHeight && imgHeight > bxHeight) || (bxWidth && imgWidth > bxWidth)) { 

     if (imgAspectRatio > bxAspectRatio) { 
      bxHeight = ~~ (imgHeight/imgWidth * bxWidth); 
     } else { 
      bxWidth = ~~ (imgWidth/imgHeight * bxHeight); 
     } 

     this.height = bxHeight; 
     this.width = bxWidth; 
     } 
    }) 
    .each(function() { 

     // Trigger load event (for Gecko and MSIE) 
     if (this.complete || isIE6) { 
     $(this).trigger("load"); 
     } 
    }); 
    }; 
})(jQuery); 
+0

¿Puedes ir a una máquina que tenga FF3 y ver si el código todavía funciona? – webdad3

+0

Funciona en FF3, también en safari, Chrome, es decir, 7, es decir, 8, (no sé si es 6 o 9) – user520300

+0

¿Qué versión de jQuery estás usando? – webdad3

Respuesta

0

añadir caso a su función dentro de su evento click

de esto (código que envió):

$(document).ready(function(){ 

$("#slideShow a").click(function() { 
var imgTitle = $(this).children('img').attr('title'); // Find the image title 
$("#thecap").html(' ' + imgTitle + ' '); 
$("#lgImage").attr('src', $(this).children('img').attr('rel')); 
$(".resizeme1").aeImageResize({ height: 372 }); 
}); 

}); 

a este

$(document).ready(function(){ 

$("#slideShow a").click(function(event) { 
var imgTitle = $(this).children('img').attr('title'); // Find the image title 
$("#thecap").html(' ' + imgTitle + ' '); 
$("#lgImage").attr('src', $(this).children('img').attr('rel')); 
$(".resizeme1").aeImageResize({ height: 372 }); 
}); 

}); 

notó el evento palabra en su segunda función ()

funcionó?

0

sólo una suposición:

$(document).ready(function(){ 
     $("#slideShow a").click(function(e) { 
      e.preventDefault(); 

      var imgTitle = $(this).children('img').attr('title'); // Find the image title 
      $("#thecap").html(' ' + imgTitle + ' '); 
      $("#lgImage").attr('src', $(this).children('img').attr('rel')); 
      $(".resizeme1").aeImageResize({ height: 372 }); 
     }); 
}); 
+0

Esto no funcionó, pero gracias. – user520300

1

Por favor, darle una oportunidad a FireQuery (para su uso con Firebug), tal vez esta herramienta podría ayudarle a encontrar el problema.

+0

No soy tan familiar con firebug o firequery, pero sé que Firebug está mostrando errores ahora al usar este código. ¿Es posible que FF4 impida que esto funcione correctamente? – user520300

0

@ user520300: También puedes probarlo en Firefox 3.6.16 instalándolo en una carpeta diferente a la que viene por defecto y managing the two versions in separate profiles (este ejemplo es de 3.0 y 3.5, pero se puede aplicar por analogía a 3.6.16 y 4.0). No olvides instalar Firebug (1.6.2) y Firequery en tu FF 3.6.16 también, luego comparando las consolas verás si hay algún problema FF4 que impida que tu código funcione bien, o simplemente es una configuración incorrecta (como en this case) que conduce a comportamientos extraños en FF4.

+0

gracias. Lo intentaré. No es tan familiar todavía con Firebug o Firequery, así que no estoy 100% seguro de seguirlo correctamente de todos modos, pero veo si puedo ver algo entre los dos. – user520300

0

buddy intente descargar el último paquete jquery e intente utilizar ese archivo js. Creo que el problema es que FF4 no admite adecuadamente los archivos js de la versión anterior. No estoy seguro, pero puedes intentarlo.

+1

OP declaró (en un Comentario) que está usando ** jquery-latest.js ** – drudge

Cuestiones relacionadas