0

.が付いた複数のアンカー タグがありrel="<img src"#"/>"ます。

いずれかをクリックする<a></a>と、別の div に大きな画像が表示されrel、fadeIn 効果を使用して値が表示されます。

私がやりたいのは、大きな画像がアンカーと同じかどうかを確認し、そうであれば効果を防ぐsrcことです。relfadeIn

 $(document).ready(function () {

   $("a.largeimg").click(function () {
     var image = $(this).attr("rel");           
     $('.main-product-image').html('<img src="' + image + '"/>');
     $('.main-product-image img').hide();
     $('.main-product-image img').fadeIn();
     return false;

     if(src == image) {

      $('.main-product-image img').show();

     }

   });
4

2 に答える 2

0

あなたの質問が正しく理解できたら、アニメーションの前に、画像の がクリックされた要素srcの属性と等しいかどうかを確認する必要があるため、アニメーションが妨げられます!rel

Jクエリ

$(document).ready(function () {

  // use bind when targeting many elements
  $("a.largeimg").bind("click", function () {

    var $target = $('.main-product-image'),         // target element
        src     = $target.find('img').attr("src"),  // src from existent image
        image   = $(this).attr("rel");              // rel from clicked element

    // if src different from image
    if (src != image) {
      $target.html('<img src="' + image + '"/>');   // append new image
      $target.find('img').hide().fadeIn();          // perform the animation
    }

    // prevent the browser from continuing to bubble the clicked element
    return false;
  });
});

追伸:

テストされていませんが、問題なく動作するはずです。

于 2012-05-24T00:58:08.460 に答える
0

アンカーの rel と画像の src が同じかどうかを確認できます。同じ場合は、フェードイン コードの前に次のように関数をエスケープします。

var src = $('.main-product-image img').attr("src");
if (src == image) return false;
于 2012-05-24T00:53:03.893 に答える