I made a jquery gallery a half year ago (SO community helped me alot cause I’m not familiar enough with js/jquery) and now I’d like to add next/previous buttons to this gallery. I tried combine it with other galleries but nothing worked properly.
here is js:
<script type="text/javascript">
function showPic (whichpic) {
if (document.getElementById) {
$('#actimg').fadeOut(170);
setTimeout(function() {
document.getElementById('actimg').src = whichpic.href;
$('#actimg').fadeIn(170);
}, 170);
return false;
} else {
return true;
}
}
</script>
and html:
<img id="actimg" src="" width="600" height="400" alt="main" />
<a onclick="return showPic(this)" href="example_1.jpg">
<img height="39px" width="58px" src="example_1.jpg" alt="thumbnail" />
</a>
<a onclick="return showPic(this)" href="example_2.jpg">
<img height="39px" width="58px" src="example_2.jpg" alt="thumbnail" />
</a>
<a onclick="return showPic(this)" href="example_3.jpg">
<img height="39px" width="58px" src="example_3.jpg" alt="thumbnail" />
</a>
gallery looks like http://www.rafsimons.com/collections/aw-11/ but it’s not flash and there are no next/prev buttons which I want to make now. Thanks in advance for help.
First add a class attribute to all your thumbs (
<a>tags) so they can be easily referred to from jQuery:We need a way to know which one is the current image. We can store that information in a custom attribute in your
<a>tag itself. For this modify your showPic function like:Now add 2 links for next/prev buttons and place them where appropriate. Give their ids as ‘next’ and ‘prev’
Now add 2 js functions nextPic() and prevPic() like:
Add this too, to initialize the first image as current by default.