2012-05-24 67 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:

没有测试,但应该工作就好了!

相关问题