16
Information:
I’m trying to make a simple photo gallery. I want to show the large-sized image in the center of the screen. (Clicar em 0.jpg e mostrar em uma outra div 0Large.jpg)
Problem:
With the code I have I can do this, but just really showing the image clicked. The problem is that this clicked image will be of a different size (it will be something like thumbnail) so clicking the image that appears is small. I want to show a great version. Ex: 001Large.jpg
instead of 001.jpg
. I don’t really know how to do this. I thought I’d use a kind of loop in the variable that contains the address of the image until she found the ". jpg" and insert before this text ". jpg" the name "Large" to display the large version of the image.
I have an HTML similar to this:
<div id="gallery-work">
<div id="gallery-warper" >
<div class="img-container" >
<img src="img/gallery/work/001.jpg" alt="" width="100%" />
</div>
<div class="img-container" >
<img src="img/gallery/work/002.jpg" alt="" width="100%" />
</div>
<div class="img-container" >
<img src="img/gallery/003.jpg" alt="" width="100%" />
</div>
<div class="img-container" >
<img src="img/gallery/004.jpg" alt="" width="100%" />
</div>
</div>
And Javascript:
$(document).ready(function () {
$("img").click(function() {
var imgLocation = $(this).attr("src");
var newImgLocation = '<div id="showimg" class="midway-horizontal midway-vertical"><img class="imgshow midway-horizontal midway-vertical" src="' + imgLocation + '"/></div>';
$(".main-container").append(newImgLocation);
Midway();
$("#showimg").click(function() {
$(this).remove();
});
});
});
Example in Jsfiddle
Obs: When clicking on the div containing the large image you should remove the image but Jsfiddle is not working.
Thanks friend, I agree with you, the best thing will be to use even a ready. I wish I could mark your answer as "Answer" but the topic question is to change the SRC and not a way to make a gallery. Eventually I’ll end up using Colorbox anyway. I had already looked at it, but I thought it would be more practical to do something simple, but it’s not as simple as just styling with CSS. Thank you!
– Pedro Gelli
This is questionable, but it does not fit here, needing we are there!
– Kenny Rafael