Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6943435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:09:20+00:00 2026-05-27T13:09:20+00:00

I made a jquery gallery a half year ago (SO community helped me alot

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:09:20+00:00Added an answer on May 27, 2026 at 1:09 pm

    First add a class attribute to all your thumbs (<a> tags) so they can be easily referred to from jQuery:

    <a class="gallery_item" onclick="return showPic(this)" href="example_1.jpg">
    <img height="39px" width="58px" src="example_1.jpg" alt="thumbnail" />
    </a>
    ...
    

    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:

    function showPic (whichpic) {
      if (document.getElementById) {
        $('.gallery_item').removeAttr('current'); // <- remove 'current' attribute from all thumbs
        $('#actimg').fadeOut(170);
        setTimeout(function() {
          document.getElementById('actimg').src = whichpic.href; 
          $('#actimg').fadeIn(170);
          $(whichpic).attr('current', '1'); // <- set this one as current
        }, 170);
        return false; 
      } else {
        return true;
      }
    }
    

    Now add 2 links for next/prev buttons and place them where appropriate. Give their ids as ‘next’ and ‘prev’

    <a href="#" id="prev" onclick="return nextPic()">Prev</a>
    
    <a href="#" id="next" onclick="return prevPic()">Next</a>
    

    Now add 2 js functions nextPic() and prevPic() like:

    function nextPic() {
      var current = null;
      $('.gallery_item').each(function() {
        if($(this).attr('current')=='1') {
        current = $(this);
        return false;
        }
      });
      if(current!=null) {
        if(current.parent().next().length!=0) {
        showPic(current.parent().next().find('.gallery_item')[0]); // <- show next pic
        }
        else {
        showPic($('.gallery_item:first')[0]); // if no next pic, show first pic
        }
      }
      return false;
    }
    
    function prevPic() {
      var current = null;
      $('.gallery_item').each(function() {
        if($(this).attr('current')=='1') {
        current = $(this);
        return false;
        }
      });
      if(current!=null) {
        if(current.parent().prev().length!=0) {
        showPic(current.parent().prev().find('.gallery_item')[0]); // <- show next pic
        }
        else {
        showPic($('.gallery_item:last')[0]); // if no next pic, show first pic
        }
      }
      return false;
    }
    

    Add this too, to initialize the first image as current by default.

    $().ready(function() {
      $('.gallery_item:first').attr('current', '1');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a image gallery with jQuery found here: http://sarfraznawaz2005.kodingen.com/demos/jquery/image_gallery/ I just wanted
I have a drop down menu made with Jquery. Right now, if you hover
now i made JavaScript code (jquery code) and when i click ok it return
I have a mobile website made in jQuery Mobile and I would like to
Here is feed for commits made in jquery project. http://github.com/feeds/jquery/commits/jquery/master This feed does not
I made a jQuery script that works fine, I'd just like to see if
I've successfully made JQuery work with Master Pages, but not JQuery UI.My header in
I made a gallery using jquery and css. I made function of changing image
I am using the Jquery serialScroll plugin and have made a horizontal gallery which
I made a jquery code like : $('button').click(function(event) { }); In it; I put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.