6

这段代码工作正常,直到我去 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 });
});

});

这是插件代码,以防有人看到其中的内容?

(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 );
4

5 回答 5

1

请尝试使用FireQuery(与Firebug一起使用),也许这个工具可以帮助您找出问题所在。

于 2011-04-07T15:50:23.510 回答
0

只是猜测:

$(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 });
        });
});
于 2011-04-07T15:40:55.963 回答
0

好友尝试下载最新的 jquery 包并尝试使用该 js 文件。我认为问题在于 FF4 不能正确支持旧版本的 js 文件。我不确定,但你可以试试。

于 2011-04-14T18:16:15.213 回答
0

@user520300:您也可以在Firefox 3.6.16中对其进行测试,方法是将其安装在与默认文件夹不同的文件夹中,并在单独的配置文件中管理两个版本(此示例适用于 3.0 和 3.5,但您可以将其应用到 3.6.16和 4.0)。不要忘记将Firebug (1.6.2)Firequery安装到您的 FF 3.6.16 中,然后通过比较控制台,您会看到是否有一些 FF4 问题阻止您的代码正常工作,或者它只是配置错误(就像在这种情况下)导致FF4中的奇怪行为。

于 2011-04-08T02:06:13.233 回答
0

在您的点击事件中向您的函数添加事件

从此(您发布的代码):

$(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 });
});

});

对此

$(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 });
});

});

注意到你的第二个函数中的单词 event()

它起作用了吗?

于 2011-06-09T03:35:15.340 回答