1

jQZoom を使用して注目の製品画像を拡大する e コマース製品ページを作成しています。ただし、代替の製品写真のサムネイルをクリックして、大きな注目の画像を置き換えるだけでなく、新しく置き換えられた注目の画像で jQZoom() 関数を再インスタンス化する機能が欲しいです。

これはすべて正常に動作します

問題はこれです。ページ読み込み時に jQZoom() が適用された元の注目の画像は、依然として「生きたアーティファクト」のままであり、置き換えられた注目の画像を hover() すると、ズーム効果が置き換えられた画像と元の画像に適用されます。 .

////////////////////////
商品ページ
//////////////////////


///////////////////////////////////////////
私の交換機能

function SwapPic(image, image_big)
{

  $(".jqZoomWindow").remove();
  $(".jqZoomPup").remove();

  $('img.feature').attr("src",image);
  $('#product-image a').attr("href",image_big).jqzoom({
      zoomWidth: 330,
      zoomHeight: 330,
      showEffect:'show',
      hideEffect:'fadeout',
      fadeoutSpeed: 'slow',
      xOffset :72,
      title :false
    });
}
4

2 に答える 2

1

jQuery 関数のような...で始めたテーマに従います。多くのコードが重複していますが、JS は完全なオブジェクト指向言語ではありません。コードの重複を避けるためにいくつかの手法を適用し、jQuery プラグインを利用できます。

スクリプトをテストする時間がありません。したがって、必要に応じて変更する必要があるものがあります。それがあなたが必要とするもののより良い近似であることを願っています.

妻jjejejeの服を買ってくれたらいくらか値引きします。

(function($) {

 $.fn.SwapPic = function(options) {

  options = $.extend({
   zoomWidth: 330,
   zoomHeight: 330,
   showEffect:"show",
   hideEffect:"fadeout",
   fadeoutSpeed: "slow",
   xOffset:72,
   title:false,
   containerImgSmall: "",
   containerImgLarge: "",
   postAccion: null
  }, options || {});

  options.pthis = this;
  options.accion = function() {  

   imageSmall = $(options.pthis).attr("href"); //verifies this line
   imageLarge = $(options.pthis).attr("href").replace(/small/, "large"); //verifies this line

   options.containerImgSmall = $(options.containerImgSmall);
   options.containerImgLarge = $(options.containerImgLarge);

   //I do not know if it's necessary to do this
   if ($(".jqZoomWindow").length != 0)
    $(".jqZoomWindow").remove();

   //I do not know if it's necessary to do this
   if ($(".jqZoomPup").length != 0)
    $(".jqZoomPup").remove();

   options.containerImgSmall.attr("src", imageSmall);

   options.containerImgLarge.attr("href", imageLarge).jqzoom({
    zoomWidth:options.zoomWidth,
    zoomHeight:options.zoomHeight,
    showEffect:options.showEffect,
    hideEffect:options.hideEffect,
    fadeoutSpeed:options.fadeoutSpeed,
    xOffset:options.xOffset,
    title:options.title
   });

   if (options.postAccion!=null)
    options.postAccion.call();
  };

  $(this).bind("click", options.accion);

 };
})(jQuery);

$(document).ready(function(){

 var myPostAccion = function(){
  $('#product-images li:first').fadeIn("slow");
 };

 $(".a-class-1").SwapPic({
  containerImgSmall: "img.feature",
  containerImgLarge: "#product-image a",
  postAccion: myPostAccion
 });

 $(".a-class-2").SwapPic({
  zoomWidth: 530,
  zoomHeight: 530,
  containerImgSmall: "img.feature",
  containerImgLarge: "#product-image a",
  postAccion: myPostAccion
 });

});

HTML:

<a class="product-thumbs a-class-1" href="http://cdn.shopify.com/s/files/1/0031/5672/products/n1_small.jpg?1252565016" ><img src="http://cdn.shopify.com/s/files/1/0031/5672/products/n1_thumb.jpg?1252565016" alt="text" /></a>
<a class="product-thumbs a-class-2" href="http://cdn.shopify.com/s/files/1/0031/5672/products/n2_small.jpg?1252565016" ><img src="http://cdn.shopify.com/s/files/1/0031/5672/products/n2_thumb.jpg?1252565016" alt="text" /></a>
于 2009-09-10T13:11:41.573 に答える
0

これは、jqzoomからデータをクリーンアップする方法です。

$('.jqclass').removeData('jqzoom');

jqzoomはこのオブジェクトにデータを保持するため:

$(el).data("jqzoom", obj);
于 2013-03-14T15:39:10.500 に答える