图片库:单击时禁用缩略图

发布于 2024-11-07 18:07:16 字数 1207 浏览 3 评论 0 原文

我正在尝试创建一个简单的“图片库”,其中有一张大照片和几个缩略图。单击缩略图时,大图像应淡出,然后淡入新图像。我的问题是,当我单击代表当前“大图像”的缩略图时,大图像会淡出并且不显示大图像。因此,我想在单击缩略图并且加载大图像后禁用缩略图。任何有关如何执行此操作的建议将不胜感激。我当前的代码如下所示:

application.js

function addClickHandlers(){
  var large_image = document.getElementById("large_image")
  var thumbnail = $('img.thumbnail')

  // Adds click handlers to image thumbnails that update the larger image
  $(thumbnail, this).click(function() {
    src = this.src.replace("thumb", "large")
    $(large_image).fadeOut(200, function(){
      $(large_image).attr('src', src).bind('readystatechange load', function(){
        if  (this.complete) $(this).fadeIn(400);
      });
    });
  });
};

$(document).ready(addClickHandlers);  

和我的 HTML/HAML

.big_photo
  = image_tag(@tee.tee_images.first.photo.url(:large), :id => "large_image")
- tee.tee_images.each do |image|
  = image_tag(image.photo.url(:thumb), :class => "thumbnail")

我已遵循本教程:http://blog.randomutterings.com/articles/2009/02/15/changing-images-with-jquery-and-the-fade-effect

I'm trying to create a simple "image gallery" where I have one big photo and a couple of thumbnails. When a thumbnail is clicked the big image should fade out and then fade in the new image. My problem is that when I click on the thumbnail that represents the current "big image" the big image fades out and no big image is displayed. I therefore want to disable the thumbnail once it's clicked and it's big image has been loaded. Any suggestions on how to do this would be greatly appreciated. My current code looks like this:

application.js

function addClickHandlers(){
  var large_image = document.getElementById("large_image")
  var thumbnail = $('img.thumbnail')

  // Adds click handlers to image thumbnails that update the larger image
  $(thumbnail, this).click(function() {
    src = this.src.replace("thumb", "large")
    $(large_image).fadeOut(200, function(){
      $(large_image).attr('src', src).bind('readystatechange load', function(){
        if  (this.complete) $(this).fadeIn(400);
      });
    });
  });
};

$(document).ready(addClickHandlers);  

And my HTML/HAML

.big_photo
  = image_tag(@tee.tee_images.first.photo.url(:large), :id => "large_image")
- tee.tee_images.each do |image|
  = image_tag(image.photo.url(:thumb), :class => "thumbnail")

I've followed this tutorial: http://blog.randomutterings.com/articles/2009/02/15/changing-images-with-jquery-and-the-fade-effect

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

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

发布评论

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

评论(1

傲鸠 2024-11-14 18:07:16

检查大图像是否与拇指匹配怎么样?所以将代码更改为

$(thumbnail, this).click(function() {
  src = this.src.replace("thumb", "large");
  if (src != large_image.src)
    $(large_image).fadeOut(200, function(){

How about checking if the big image matches the thumb? so change the code to

$(thumbnail, this).click(function() {
  src = this.src.replace("thumb", "large");
  if (src != large_image.src)
    $(large_image).fadeOut(200, function(){
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文