0
votes

At this current iteration, I have it where if a user clicks on an image thumbnail, the thumbnail image displays in a different div (the main div) and in doing so, it rewrites the main div img src attr with the thumbnail img attr minus the "-thumbnail". This part is good, or at least I believe it is.

With that said, after the user clicks on a thumbnail and the main div img appears, it lingers...and what I mean by lingers is that for example, if a user closes the div and re-opens it or another div just like it, the last image shows (stays) when it shouldn't in the main div. Instead, it should be showing the first thumbnail img in the main div...

Any suggestions is appreciated and below is what I currently have (or at least a portion of it). There is a lot more, but below is the main stuff that's giving me troubles...

The HTML part is within a div class called "t_1". I have 24 of these..."t_1", "t_2", "t_3" respectively. And within this class, I have what is posted below in all using the same div classes. The only difference is the folder names in the img tag.

So, when a user clicks on that thumbnail and that thumbnail image gets rewritten so that it can be displayed in the main div "t_main_screenshot", all is good...but then, if the user clicks out of the "t_1" etc. divs, and opens up another "t_2", that last image thumbnail that was clicked previously shows in the main div (t_main_screenshot) instead of the first image thumbnail for what should be in "t_2"...

Hopefully this is a bit better in clarity...It's kind of hard to explain.

HTML:

<div class="t_main_screenshot">
    <img src="_framework/images/slides/simplicity/2.png" alt="" title="" />
</div>

<div class="t_thumbnail_wrapper">
    <div class="t_thumbnail active">
        <img src="_framework/images/slides/simplicity/2-thumbnail.png" alt="" title="" />
    </div>
    <div class="t_thumbnail">
        <img src="_framework/images/slides/simplicity/4-thumbnail.png" alt="" title="" />
    </div>
    <div class="t_thumbnail">
        <img src="_framework/images/slides/simplicity/6-thumbnail.png" alt="" title="" />
    </div>
</div>

JS/JQuery:

$('.t_thumbnail').click(function() {
    $('.t_thumbnail').removeClass('active');
    $(this).addClass('active');

    var thumbNail = $(this).find('img').attr('src');

    $('.t_main_screenshot img').fadeOut(0, function() {
        $(this).fadeIn().css('animation','scale-in .75s ease-in 0s forwards')[0].src = thumbNail.replace('-thumbnail', '');
    });
});
2
So I would iterate my understanding: You have divs with image and 1 main div. Clicking on these divs would set its image as main. But when user clicks on second div, this image is not updated. Am I right?Rajesh
Close. I edited my original post. Hopefully by doing so, it's more understandable...This Guy
Have tried replacing selected image first and then do fadeIn() and css()?Fawkes
BCoder, I think I need an if/else statement somewhere but I'm not entirely sure how to accomplish this...This Guy
try this : $(this).attr('src',thumbNail.replace('-thumbnail', '')).fadeIn().css('animation','scale-in .75s ease-in 0s forwards');Fawkes

2 Answers

1
votes

Try this code :

$('.t_thumbnail').click(function() {
	$('.t_thumbnail').removeClass('active');
	$(this).addClass('active');
	
	var thumbNail = $(this).find('img').attr('src');
	
	$(this).parent().parent().siblings().find('.t_main_screenshot').children('img').fadeOut(0, function() {
		$(this).fadeIn().css('animation','scale-in .75s ease-in 0s forwards')[0].src = thumbNail.replace('-thumbnail', '');
	});
});

As you are updating directly on .t_main_screenshot class. So it will update all places, in this case in all your modals .t_1, .t_2, ...etc.

0
votes
$('a.screenshots_1').click(function() {
    $('.t_main_screenshot img').find('img').attr('src' , "");
});

This will help you to initialize the main screenshot on modal screenshot icon click.