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 8270467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:34:25+00:00 2026-06-08T06:34:25+00:00

So I have this very simple (and probably not built the recommended way) image

  • 0

So I have this very simple (and probably not built the recommended way) image slider at my wordpress page that I built myself. My problem is that when the images run out, it will just slide whitespace, and so on. I want it to start sliding from the beginning, or just stop sliding at the last image. Here’s my code:
HTML:

<div id="gallery-wrap">
   <div id="gallery">
      <img class="galleryimage" src="http://materiaalit.kotisivut.name/sivustokuvat/ccc.PNG" alt="" />
      <img class="galleryimage2"  src="http://materiaalit.kotisivut.name/sivustokuvat/coverline.PNG" alt="" />
      <img class="galleryimage3"  src="http://materiaalit.kotisivut.name/sivustokuvat/ccc.PNG" alt="" />
      <img class="galleryimage4"  src="http://materiaalit.kotisivut.name/sivustokuvat/coverline.PNG" alt="" />
   </div>
    <div id="gallery-controls">
      <a id="gallery-prev" href="#"><img alt="" /> </a>
      <a id="gallery-next" href="#"><img alt="" /></a></div>
    </div>
</div>

CSS:

#gallery-wrap{margin: 0 auto; overflow: hidden; width: 100%; position: relative; height:300px; border:1px solid black; border-radius:6px; z-index:3;}
#gallery{position: relative; left: 0; top: 0; width:100%;}
.galleryimage{position:absolute; width:100%; height:300px; top:0px;}
.galleryimage2{position:absolute; width:100%; height:300px; left:100%;top:0px;}
.galleryimage3{position:absolute; width:100%; height:300px; left:200%;top:0px;}
.galleryimage4{position:absolute; width:100%; height:300px; left:300%;top:0px;}

#gallery-controls{width: 100%; z-index:4;}
#gallery-prev{position:absolute; left:0px; top:0px; width:50%; height:300px; }
#gallery-next{position:absolute; right:0px; top:0px;  width:50%; height:300px;}

And the js/jquery

var position = 1; // you always start at the first image?
$(document).ready(function()
{
  $("#gallery-prev").click(function(){

    var nr_of_img = $('img', $('#gallery')).length;

    if (position == 1)
    { 
      // move all the way to the last image
      position = nr_of_img;
    }
    else
    {$("#gallery").animate({"left": "+=100%"}, "slow");
      // move to the previous image
      position--;
    }
  });

  $("#gallery-next").click(function(){

    var nr_of_img = $('img', $('#gallery')).length;

    if (position == nr_of_img)
    { 
      // move all the way to the first image
      position = 1;
    }
    else
    {$("#gallery").animate({"left": "-=100%"}, "slow");
      // move to the previous image
      position++;
    }
  });
});

So as you can probably see, I’m thinking what to put in the variables. How does the script know when the images run out? And as you can see, the images are absolutely positioned, that was the easiest way to get them all to the same horizontal line.
If anyone wants to see this in action:
http://wordpress.kotisivut.name/

  • 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-08T06:34:26+00:00Added an answer on June 8, 2026 at 6:34 am

    Why don’t you count the amount of images in your slider…

    var nr_of_img = $('img', $('#gallery')).length;
    

    Then you can keep count of the number of moves you make from left to right etc and see if you ran out of images.

    [Edit]

    first of all your if-statements are at the wrong place. You want to do the if-statements in the event functions.

    This would mean you would do something like this

    var position = 1; // you always start at the first image?
    $(document).ready(function()
    {
      $("#gallery-prev").click(function(){
        var nr_of_img = $('img', $('#gallery')).length;
    
        if (position == 1)
        {
          // move all the way to the last image
          position = nr_of_img;
        }
        else
        {
          // move to the previous image
          position--;
        }
      });
    
      $("#gallery-next").click(function(){
        var nr_of_img = $('img', $('#gallery')).length;
    
        if (position == nr_of_img)
        {
          // move all the way to the first image
          position = 1;
        }
        else
        {
          // move to the previous image
          position++;
        }
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, this is probably very simple but, I have the below checks (not at
I have this very simple br2nl function that I use to take a string
I have this very simple example that I am using to learn structs in
I have this scala application which is very simple . All that it does
I have this html page which is very simple, it contains a text box
Okay this question is very simple: I have a facebook page, and a website.
This is probably a very simple answer, but I'm not seeing an obvious solution
The solution to this is probably very simple, but I'm not sure what I'm
This is probably a simple question, but I'm not very good at PostGIS and
I have a question that will probably have a very simple solution. I'm running

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.