2011-10-31 6 views
1

サムネイルの置き換えソリューションがあります。imgアイテムの周りにaタグを追加する必要がありますが、同じ機能があります。jQuery thumbnail replaceメソッド(タグを追加するソリューションが必要)

jQueryの

$(".large").click(function() { 
    var thumbRel = $(this).attr("rel"); 
    $(this).effect("transfer", { to: $(".thumbnail img[rel='" + thumbRel + "']") }, 1000); 
}); 

$(".thumb").click(function() { 
    $(".thumbnail [class^='thumb']").removeClass("current"); 
    $(this).addClass("current"); 
    $(".large").attr("rel", $(this).attr("rel")); 

    $(this).effect("transfer", { to: $(".large") }, 1000); 
    $(".large").animate({ opacity: 1 }, 1000); 
    $(this).queue(function() { 
     $(".large").attr("src", $(this).attr("src").replace("-thumb", "")); 

     $(".large").animate({ opacity: 1 }, 1000); 
     $(this).dequeue(); 
    }); 
}); 

画像はクリック可能である全体のdivを持つように、されたマークアップは、ドットネットと混合されるが、ここでは

<div class="product_images">   
    <div class="mainImage">    
     <a class="ShowProductImageDlg" href="#" onclick="ProductImagesDlgClientSide.showDialog('@Model.ProductToDisplay.Product.UrlSlug', 'Bottle'); return false;" > 
      <img class="LargeImage" src="@Model.ProductToDisplay.Product.awsImageUrlLarge" alt="@Model.ProductToDisplay.Product.ProductName" /> 
     </a>    
    </div> 
    <strong>Additional Images</strong> 
    <div class="thumbnail"> 
     <ul> 
      <li><a href=""><img class="SmallImage Bottle" src="@Model.ProductToDisplay.Product.awsImageUrlSmall" 
        alt="@Model.ProductToDisplay.Product.ProductName" /></a></li>     

      <li><a href=""><img class="SmallImage BackLabel" src="@Model.ProductToDisplay.ProductAdditionalImageUrlSmall(awsProductImageType.BackLabel)" 
        alt="@Model.ProductToDisplay.Product.ProductName" /></a></li>    
     </ul> 
    </div>  
</div> 

最終目標であります(それは90pxで90pxです)画像自体が80x35である場合。

同じjQueryを使用したいと思います。

答えて

0

あなたはそのようにこれを行うことができます(see jsfiddle as a proof):基本的に

var link = jQuery('<a>', { 
    'href': 'http://www.google.com/', 
    'title': 'Dynamically generated link' 
}); 

jQuery('img').wrap(link); 

あなたが最初 (リンク<a>要素)を作成し、 imgセレクタで選択された画像のまわりでそれをラップすることができますあなたのニーズに合わせて調整してください)。

+0

申し訳ありません、 私はdisplay:blockを要素に置いて、ボックス全体をクリック可能にすることができます。が必要です。 (90x90px)、画像は80x35です。 どこにでもサムネイルをリンクさせたくありません。 – rizzy

+0

'display:block;を適用するだけです。カーソル:ポインタ;を画像に追加し、それらにパディングを追加します。プレゼンテーション以外の目的でラッピングするための要素を作成することは何の意味もありません。 –

関連する問題