简体   繁体   English

jQuery-尝试创建可在单击缩略图时滑入视图的图库

[英]Jquery - trying to create a image gallery that slides in to view upon clicking thumbnail

I've been trying to figure out how to create my own custom image gallery for my portfolio website to no avail. 我一直在试图弄清楚如何为我的投资组合网站创建自己的自定义图片库,但无济于事。

I have a div that holds my thumbnails for my different images. 我有一个div,其中包含用于不同图像的缩略图。 The CSS code for this div is as follows: 该div的CSS代码如下:

.gallery {
width: 900px;
height: 600px;
background-color: white;
margin: 50px;
float: left;
box-shadow: 3px 3px 20px #000000;
position: relative;

I've created another div which is #project_display that is absolutely positioned -900px to the left of the gallery div. 我创建了另一个div,它是#project_display ,绝对位于画廊div的左侧-900px处。 This div is also set to width: 900px and height: 600px; 该div也设置为width:900px和height:600px;

What I'm trying to do is take the anchored link of the thumbnails (which are the larger version images of the thumbnails) and dynamically Fill this outlying div with the larger image as it animates in. It's hard to explain. 我想做的是获取缩略图的锚定链接(这是缩略图的较大版本的图像),并在动画中以较大的图像动态填充此div的外部div。这很难解释。 Below is the code, hopefully that makes it more clear: 下面是代码,希望可以使其更加清晰:

$('.projects').bind('click', function(event){
    $('#project_display').animate({
        left:'0px'
        });
        event.preventDefault();

        var this_project = $('.projects').each(function(){
            $(this).children('a[href]');
        })

        $('#project_display').html('<img src="'+this_project+'"/>');
    })

The anchor link to the large image is not being put into the outlying div. 指向大图片的锚点链接未放入外围div。

Can someone tell me what I'm doing wrong? 有人可以告诉我我在做什么错吗? because I clearly am not doing something right. 因为我显然做错了什么。

$('.projects').bind('click', function(event){
       var aHref= $(this).attr("href");
       $('#project_display').html('<img src="'+aHref+'"/>');
       $('#project_display').animate({
           left:'0px'
       });
 });

Try the above one. 试试上面的一个。 If not works Please Provide HTML also, that will increase the understanding of code. 如果不起作用,请也提供HTML,这将增加对代码的理解。 So I will help you to fix the problem. 因此,我将帮助您解决问题。

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

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