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

  • SEARCH
  • Home
  • 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 8253935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:02:54+00:00 2026-06-08T01:02:54+00:00

Please excuse the poorly worded title, hopefully I can explain the issue here. I’ve

  • 0

Please excuse the poorly worded title, hopefully I can explain the issue here.

I’ve written a simple gallery control in jQuery, there’s six images with two button controls that allow the user to cycle through a total collection of images. I have this part working fine but whenever I click a button to move through the collection the page ‘jumps/scrolls’ automatically to the top of the page? I’ve tried giving the gallery container a fixed height as I had a similar issue before which I managed to solve doing this but this hasn’t helped:

Here is the jQuery:

var index = 0;
$(function () {
    $('#btnLeft').click(function () {
        if (index != 0) {
            index--;
            $('#sixth').attr('src', $('#fifth').attr('src'));
            $('#fifth').attr('src', $('#fourth').attr('src'));
            $('#fourth').attr('src', $('#third').attr('src'));
            $('#third').attr('src', $('#second').attr('src'));
            $('#second').attr('src', $('#first').attr('src'));
            $('#first').attr('src', '/Content/Images/Gallery/Thumbs/' + parseInt(index + 1) + '.png');
        }
    });

    $('#btnRight').click(function () {
        if (parseInt(6 + index) != 10) {
            index++;
            $('#first').attr('src', $('#second').attr('src'));
            $('#second').attr('src', $('#third').attr('src'));
            $('#third').attr('src', $('#fourth').attr('src'));
            $('#fourth').attr('src', $('#fifth').attr('src'));
            $('#fifth').attr('src', $('#sixth').attr('src'));
            $('#sixth').attr('src', '/Content/Images/Gallery/Thumbs/' + parseInt(6 + index) + '.png');
        }
    });
});

Here is the markup:

<div id="gallerySlider" style="height: 160px;">
    <img id="first" src="/Content/Images/Gallery/Thumbs/1.png" alt="Image" width="160" height="160" style="float:left;" /> 
    <img id="second" src="/Content/Images/Gallery/Thumbs/2.png" alt="Image" width="160" height="160" style="float:left;" />
    <img id="third" src="/Content/Images/Gallery/Thumbs/3.png" alt="Image" width="160" height="160" style="float:left;" />
    <img id="fourth" src="/Content/Images/Gallery/Thumbs/4.png" alt="Image" width="160" height="160" style="float:left;" />
    <img id="fifth" src="/Content/Images/Gallery/Thumbs/5.png" alt="Image" width="160" height="160" style="float:left;" />
    <img id="sixth" src="/Content/Images/Gallery/Thumbs/6.png" alt="Image" width="160" height="160" style="float:left;" />

    <a id="btnLeft" style="position:relative; float:left; bottom:105px;" href="#"><img src="/Content/Images/Design/leftbutton.png" alt="Left Button" /></a>
    <a id="btnRight" href="#" style="position:relative; float:right; bottom:105px;"><img src="/Content/Images/Design/rightbutton.png" alt="Right Button" /></a>
</div> 

Can anyone offer advice?

Thanks

  • 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-06-08T01:02:57+00:00Added an answer on June 8, 2026 at 1:02 am

    Use .preventDefault() like following to stop browser default load and jump:

    $('#btnLeft').click(function (e) {
    
            e.preventDefault();
    
            if (index != 0) {
                index--;
                $('#sixth').attr('src', $('#fifth').attr('src'));
                $('#fifth').attr('src', $('#fourth').attr('src'));
                $('#fourth').attr('src', $('#third').attr('src'));
                $('#third').attr('src', $('#second').attr('src'));
                $('#second').attr('src', $('#first').attr('src'));
                $('#first').attr('src', '/Content/Images/Gallery/Thumbs/' + parseInt(index + 1) + '.png');
            }
        });
    
        $('#btnRight').click(function (e) {
    
            e.preventDefault();
    
            if (parseInt(6 + index) != 10) {
                index++;
                $('#first').attr('src', $('#second').attr('src'));
                $('#second').attr('src', $('#third').attr('src'));
                $('#third').attr('src', $('#fourth').attr('src'));
                $('#fourth').attr('src', $('#fifth').attr('src'));
                $('#fifth').attr('src', $('#sixth').attr('src'));
                $('#sixth').attr('src', '/Content/Images/Gallery/Thumbs/' + parseInt(6 + index) + '.png');
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please excuse me if I'm simple here, I want to create a simple widget
Please excuse the awkward title I'll try my best to explain my peculiar problem.
Please excuse the horrible title. I've been banging my head against this issue all
Please excuse the vagueness of my title, I really don't know how to succinctly
Please excuse the confusing title ;) We've built an ASP.NET MVC application to replace
Please excuse me if there are already answers to this, but I can't quite
Please excuse me but I didn't know to give a name to the title
Hello (please excuse me for my ugly english :p), Imagine these two simple models
Please excuse the vague question title, but usually I don't do such kind of
Please excuse (or improve the title) but I have a silly little problem that's

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.