views:

55

answers:

1

Hello,

I have made a image gallery with jquery found here:

http://sarfraznawaz2005.kodingen.com/demos/jquery/image_gallery/

I just wanted to know how to i add functionality to prev and next arrow images to show next and previous images with jquery.

Thanks.

+1  A: 

use prev and next to find an element before/after the current one and activate it. You will need to decouple element activation code from the onclick event.

you're using

 $(...).click(function() {
     code
     that 
     activates
     "this"
 });

but now you need to reuse the activation code, so decouple it

 activate = function(elem) {
     code
     that 
     activates
     "elem"
 }

 $(img).click(function() {
     activate(this)
 });

 $(#left).click(function() {
     activate(currentElement.prev())
 });

 $(#right).click(function() {
     activate(currentElement.next())
 });
stereofrog
+1: thanks i am alredy using that but having some problems. Ok what do you mean by decouple element activation code?
Sarfraz
see edit/......
stereofrog