jqzoom 对多个图像进行缩放

发布于 2024-10-21 16:34:59 字数 831 浏览 0 评论 0原文

我有一张主图像和多个缩略图的标准设置,可以单击这些缩略图来更改主图像。我在主图像上使用 jqzoom,但遇到了主图像更改和缩放图像变成空白的常见问题。通过查看堆栈溢出,我发现了一些声称可以纠正此问题的代码,并且在某种程度上确实如此。但它并没有允许每个更改的图像进行缩放,而是使主图像只是到大版本的链接,绕过 jqzoom 函数调用。

显示两个示例: 使用标准 jqzoom 代码和缩略图不显示缩放: http://designerspider.net/clients/jge/project2.php?id=17

添加的代码和图像刚刚成为链接: http://designerspider.net/clients/jge/project.php?id=17

我添加的代码是

 $(".thumbs a").click(function(){  
      $(".jqclass").unbind();

      $(".jqclass").jqzoom(options);

      return false;
  };

如果有人可以看到我是否错过了任何内容,或者需要以不同的方式进行操作,我将不胜感激。我不明白为什么添加额外的功能会禁用主要的 jqzoom 功能:/

I have the standard setup of one main image and multiple thumbnails which can be cliced to change the main image. I'm using jqzoom on the main image but was having the common problem of the main image changing and the zoomed image just going blank. Looking through stack overflow i found some code that claimed to correct this, and in a way it does. But rather than allow each changed image to have a zoom, it makes the main image just a link to the large version, bypassing the jqzoom function call.

to show the two examples:
with the standard jqzoom code and thumbnails not showing zooms:
http://designerspider.net/clients/jge/project2.php?id=17

with added code and images just becoming links:
http://designerspider.net/clients/jge/project.php?id=17

the code i added was

  $(".thumbs a").click(function(){  
      $(".jqclass").unbind();

      $(".jqclass").jqzoom(options);

      return false;
  };

if anyone can see if i have missed anything, or need to do it a diffferent way, i'd appreciate any and all advice. I can't understand why adding the extra function would disable the main jqzoom feature :/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

他夏了夏天 2024-10-28 16:34:59

您可能会发现,由于您同时使用两个功能,一个用于更改图像,另一个用于取消绑定缩放功能,然后重新绑定它,所以第二个功能在图像更改之前完成。所以当图像确实改变时,它仍然不起作用。

第二个问题,你实际上并没有解除任何东西的绑定。

因此,首先尝试更改为:

$(".jqclass").unbind(".jqclass");

或者,您可以将更多内容迁移到 jQuery。我已经测试过这个:

你的 HTML 看起来像这样:

<div class="projectphotos">
    <div id="photo_1">
        <a href="http://designerspider.net/clients/jge/projects/h07_03_11_12_10_58.jpg" class="jqclass">
            <img src="http://designerspider.net/clients/jge/projects/h07_03_11_12_10_58.jpg" class="projectimg2" alt="Mid 15th C Oakeshott Type XXa" />
        </a>
    </div>
    <div id="photo_2" style="display:none;">
        <a href="http://designerspider.net/clients/jge/projects/h07_03_11_12_19_49.jpg">
            <img src="http://designerspider.net/clients/jge/projects/h07_03_11_12_19_49.jpg" class="projectimg2" alt="Mid 15th C Oakeshott Type XXa" />
        </a>
    </div>                                       
    <div class="thumbsdiv">
        <ul class="thumbs">
            <li>
                <img rel="photo_1" src="http://designerspider.net/clients/jge/projects/h07_03_11_12_10_58.jpg" width="80" />
            </li>
            <li>
                <img rel="photo_2" src="http://designerspider.net/clients/jge/projects/h07_03_11_12_19_49.jpg" width="80" />
            </li>
        </ul>
    </div>
</div>

你的 jQuery 像这样,我已经解释了每一行:

var options = {
    zoomWidth: 250,
    zoomHeight: 250,
    position: 'right',
    yOffset: 0,
    xOffset: 0,
    title: false
}
$(".jqclass").jqzoom(options);

// Make the thumbnail look clickable:
$(".thumbs img").each(function() {
    $(this).css('cursor', 'pointer');
});
// React to clicking on a thumbnail:
$(".thumbs img").click(function() {
    // Get the photo linked to:
    var photo = $(this).attr('rel');
    // Unbind the zoom:
    $(".jqclass").unbind(".jqclass");
    // Hide the current image via its parent DIV:
    $(".jqclass").parent().hide();
    // Remove teh jqclass:
    $(".jqclass").removeClass("jqclass");
    // Show the clicked photo:
    $("#"+photo).show();
    // Add the class and the zoom:
    $("#"+photo+" a").addClass("jqclass").jqzoom(options);
});

You may find, because you are using two functions side by side, one to change images, and the other to unbind the zoom function, and then rebind it, the 2nd function is finishing before the image has changed. So when the image does change, it still won't work.

Second problem, you are not actually unbinding anything.

So, try firstly changing to:

$(".jqclass").unbind(".jqclass");

Alternatively you could migrate a little more to jQuery. I have tested this:

You HTML would look like this:

<div class="projectphotos">
    <div id="photo_1">
        <a href="http://designerspider.net/clients/jge/projects/h07_03_11_12_10_58.jpg" class="jqclass">
            <img src="http://designerspider.net/clients/jge/projects/h07_03_11_12_10_58.jpg" class="projectimg2" alt="Mid 15th C Oakeshott Type XXa" />
        </a>
    </div>
    <div id="photo_2" style="display:none;">
        <a href="http://designerspider.net/clients/jge/projects/h07_03_11_12_19_49.jpg">
            <img src="http://designerspider.net/clients/jge/projects/h07_03_11_12_19_49.jpg" class="projectimg2" alt="Mid 15th C Oakeshott Type XXa" />
        </a>
    </div>                                       
    <div class="thumbsdiv">
        <ul class="thumbs">
            <li>
                <img rel="photo_1" src="http://designerspider.net/clients/jge/projects/h07_03_11_12_10_58.jpg" width="80" />
            </li>
            <li>
                <img rel="photo_2" src="http://designerspider.net/clients/jge/projects/h07_03_11_12_19_49.jpg" width="80" />
            </li>
        </ul>
    </div>
</div>

And your jQuery like this, I've explained each line:

var options = {
    zoomWidth: 250,
    zoomHeight: 250,
    position: 'right',
    yOffset: 0,
    xOffset: 0,
    title: false
}
$(".jqclass").jqzoom(options);

// Make the thumbnail look clickable:
$(".thumbs img").each(function() {
    $(this).css('cursor', 'pointer');
});
// React to clicking on a thumbnail:
$(".thumbs img").click(function() {
    // Get the photo linked to:
    var photo = $(this).attr('rel');
    // Unbind the zoom:
    $(".jqclass").unbind(".jqclass");
    // Hide the current image via its parent DIV:
    $(".jqclass").parent().hide();
    // Remove teh jqclass:
    $(".jqclass").removeClass("jqclass");
    // Show the clicked photo:
    $("#"+photo).show();
    // Add the class and the zoom:
    $("#"+photo+" a").addClass("jqclass").jqzoom(options);
});
清风疏影 2024-10-28 16:34:59

这是从 jQZoom 中清理数据的方法:

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

因为 jQZoom 按以下方式保存对象数据:

$(el).data("jqzoom", obj);

This is how you can clean the data from jQZoom:

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

Because jQZoom saves the object data the following way:

$(el).data("jqzoom", obj);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文