开发者

How to add prev/next buttons to a jQuery image gallery? [closed]

开发者_开发技巧 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

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.


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())
 });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜