2012-05-24 121 views
0

我有一個rel="<img src"#"/>"多個錨標籤。僅在第一次點擊時點擊動畫點擊?

當我點擊任何<a></a>時,我使用淡入效果在另一個div中顯示rel值的大圖。

我想要做的是檢查大圖像是否具有與錨點的rel相同的src,如果是,則防止fadeIn效果。

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

    } 

    }); 
+0

很難理解你的問題。試着讓它更清楚:)或者展示這個例子來更好地理解它。 –

回答

0

您可以檢查錨的版本和圖像的src是相同的,如果代碼中淡出,像這樣以前那麼逃脫功能:

var src = $('.main-product-image img').attr("src"); 
if (src == image) return false; 
0

如果我沒有理解你問題正確,在動畫之前你需要確認圖像的src是否等於點擊元素的rel屬性,從而防止動畫!

JQUERY

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

PS:

沒有測試,但應該工作就好了!

相關問題