Jquery Image gallery with Next/Previous buttons doesn't work correctly -
i'm trying create slide gallery of images. doesn't need run automatically. want have previous , next button user can navigate manually.
my problem code doesn't work. next button, jumps second image , never goes remaining image when try clicking again. previous button when clicked, should show last image or previous 1 doesn't.
please me out. see code here
your problem not removing previous class before add current item. once you've hit next, have 2 items previous , finds first one.
$('.next').click(function(event){ event.preventdefault(); $('.previous').removeclass('previous'); $('.current').removeclass('current').addclass('previous'); $('.previous').hide("slide",{direction: 'left'}, 500); var previousid = parseint($('.previous').attr('id')); $('#'+(previousid+1)).show("slide", {direction: 'right'}, 500).addclass('current'); }); $('.prev').click(function(event){ event.preventdefault(); $('.previous').removeclass('previous'); $('.current').removeclass('current').addclass('previous'); $('.previous').hide("slide",{direction: 'right'}, 500); var previousid = parseint($('.previous').attr('id')); var id = parseint($('.current').attr('id')); $('#'+(previousid-1)).show("slide", {direction: 'left'}, 500).addclass('current');
once have fixed, you'll need take care of case you've hit last image. want stay on image, or circle around?
Comments
Post a Comment