Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialtroy beckett
12,035 Pointsimage gallery :
Hi I'm currently trying to make an image gallery for a website. At the moment I don't really care about the look as I'm quite good at styling I really just want to get the functionality right. Heres what I got so far below:
http://port-80-rzczno273y.treehouse-app.com/
I want to now make the arrows clickable so that when clicked left or right they shift to the next picture to the order of the thumbnails above. I'm currently finding javascript and jquery difficult so I guess I'm looking for some general direction or help but of course I will try to work it out alone as well. I want to be able to click the arrows and achieve what this website is achieving :
http://www.sandrageringinc.com/artists/nancy-dwyer/
heres my code below so far if interested:
html code
<body>
<div id="container">
<div id="gallery">
<a href="img/large/dotted-large.jpg"><img src="img/small/dotted-small.jpg"</a>
<a href="img/large/gold-large.jpg"><img src="img/small/gold-small.jpg"</a>
<a href="img/large/purple-large.jpg"><img src="img/small/purple-small.jpg"</a>
<a href="img/large/dotted-large.jpg"><img src="img/small/dotted-small.jpg"</a>
<a href="img/large/gold-large.jpg"><img src="img/small/gold-small.jpg"</a>
<a href="img/large/purple-large.jpg"><img src="img/small/purple-small.jpg"</a>
<a href="img/large/dotted-large.jpg"><img src="img/small/dotted-small.jpg"</a>
<a href="img/large/gold-large.jpg"><img src="img/small/gold-small.jpg"</a>
<a href="img/large/purple-large.jpg"><img src="img/small/purple-small.jpg"</a>
<a href="img/large/dotted-large.jpg"><img src="img/small/dotted-small.jpg"</a>
<a href="img/large/gold-large.jpg"><img src="img/small/gold-small.jpg"</a>
<a href="img/large/purple-large.jpg"><img src="img/small/purple-small.jpg"</a>
</div>
<div id="photo">
<a class="next" href="#">→</a>
<a class="prev" href="#">←</a>
</div>
</div>
</body>
jquery code
$(document).ready(function() {
$('#gallery a').click(function(evt) {
//don't follow link
evt.preventDefault();
//get path to new image
var imgPath = $(this).attr('href');
//get reference to old image
var oldImage = $('#photo img');
//create HTML for new image
var newImage = $('<img src="' + imgPath +'">');
//make new image invisible
newImage.hide();
//add to the #photo div
$('#photo').prepend(newImage);
//fade in new image
newImage.fadeIn(1000);
//fade out old image and remove from DOM
oldImage.fadeOut(1000,function(){
$(this).remove();
});
}); // end click
$('#gallery a:first').click();
}); // end ready
1 Answer
geoffrey
28,736 PointsHi there, I can't access your project using this link you posted. Anyway, I know a good little tutorial to build a "similar project" which goes step by step to achieve what you want.
This little tut is on the codeacademy website, which is free. It's inside the "Make an interactive website" project / DOM manipulation. Check this here.
Once you 've seen this, you'll be able to create your photo gallery, in this case It demonstrates how to build a little slider, but the principle, with the clickable arrows is the same.