简体   繁体   English

jQuery图库

[英]jQuery photo gallery

I have implemented a photo album which present a series of image thumbnails (of 200px) in a Web page but I also want to allow the user to display full-size views of the pictures by clicking on the thumbnail. 我实现了一个相册,该相册在网页中显示一系列图像缩略图(200像素),但我也想允许用户通过单击缩略图来显示图片的全尺寸视图。 The full-size view should be displayed in the same page by hiding the thumbnail index. 通过隐藏缩略图索引,应在同一页面中显示完整视图。 So once the user closes the full size image, the thumbnail index is displayed again. 因此,一旦用户关闭了全尺寸图像,便会再次显示缩略图索引。 I have the following code that reads all the pictures from a JSON file and append them to the div#images and apply CSS to them with img {height:200px, width:200px}. 我有以下代码,该代码从JSON文件中读取所有图片,并将它们附加到div#images上,并使用img {height:200px,width:200px}将CSS应用于它们。

var imageList;
$.getJSON('images.json', function(data) {
    imageList = data;
    for (var i = 0; i < imageList.length; i++) {
        $('<img>').attr({src: imageList[i].img_src, 
                    title: imageList[i].title}).appendTo('#images');    
    }
});

I am new in jQuery and want to do the task above so any answer on how to do it would be appreciated. 我是jQuery的新手,想做上面的任务,所以对如何做的任何回答将不胜感激。 Thank you in advance. 先感谢您。

Please try this: 请尝试以下方法:

Replace <img> as img.

change this, 改变这个

$('<img>').attr({src: imageList[i].img_src, 
                    title: imageList[i].title}).appendTo('#images'); 

use this, 用这个,

$('img').attr({src: imageList[i].img_src, 
                title: imageList[i].title}).appendTo('#images'); 

Take a look at what I'm doing here and reverse engineer it to suit your needs: http://oregonadventuretours.com/ 看看我在这里做什么,然后对其进行反向工程以满足您的需求: http : //oregonadventuretours.com/

Notice how I'm just showing and hiding a div with more content in it, in your case, it would be the larger photo. 请注意,我是如何显示和隐藏包含更多内容的div,在您的情况下,它将是较大的照片。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM