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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:07:29+00:00 2026-05-19T15:07:29+00:00

I am trying to create a slider in jquery and stuck in the end.

  • 0

I am trying to create a slider in jquery and stuck in the end.

I have created a <ul> and then 4 <li> in that <ul> representing each <li> a slide. When I click on next button slide 1 is animated to slide 2. When ever I click on next button current slide is animated to next one. But how do I animate last slide to load 1st slide.

I’m changing left property’s value to animate among slides. Code is given below. Please guide me. Thanks!

        current = 0;

        current_slide=1;

        $(document).ready(function(){
            var totalSlides=$(".slider ul li").length;
            $(".slider ul").removeAttr('width');
            $(".slider ul").attr('width',951*totalSlides);

            $('#next img').click(function(){
                current_slide++;
                current -= 951;
                if(current_slide>totalSlides)
                    {
                        current=0;
                        current_slide=1;
                        $(".slider ul").css('left',0);      
                    }
                $(".slider ul").animate({"left":current+"px"}, "slow");
            });

       /* Previous button is not fully functional yet*/
            $('#prev img').click(function(){
                current_slide--;
                current += 951;
                if(current_slide==1)
                    {current=0;current_slide=totalSlides;}
                $(".slider ul").animate({"left":current+"px"}, "slow");
            });
        });
  • 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-19T15:07:30+00:00Added an answer on May 19, 2026 at 3:07 pm

    I’m not sure what you mean by “load 1st slide”, the code you have should appear to rewind when you get to either end of your slides. But from looking at your code, if you just remove $(".slider ul").css('left',0); it should work.

    Also, in the previous code, I changed the current number from zero to 951 * totalSlides to position it in the right place – I haven’t tested it, so it might need to be 951 * (totalSlides - 1).

        current = 0;
    
        current_slide=1;
    
        $(document).ready(function(){
            var totalSlides=$(".slider ul li").length;
            $(".slider ul").removeAttr('width');
            $(".slider ul").attr('width',951*totalSlides);
    
            $('#next img').click(function(){
                current_slide++;
                current -= 951;
                if(current_slide>totalSlides)
                    {
                        current=0;
                        current_slide=1;    
                    }
                $(".slider ul").animate({"left":current+"px"}, "slow");
            });
    
       /* Previous button is not fully functional yet*/
            $('#prev img').click(function(){
                current_slide--;
                current += 951;
                if(current_slide==1)
                    {
                        current = 951 * totalSlides;
                        current_slide = totalSlides;
                    }
                $(".slider ul").animate({"left":current+"px"}, "slow");
            });
        });
    

    Also note that there is a bug in the jQuery animate when you have left negatively positioned > 10,000 pixels – it is scheduled to be fixed in version 1.5. So if you use a lot of slides, I’d recommend switching your code to use scrollLeft


    Update:

    Well if you want an infinite slider, there are two methods you can use:

    1. Stack all of your slides and hide all but the current one. When the user clicks the next or prev button, position the next slide on the appropriate side and slide the current one out of view and the new one into view – check out this jQuery Slider which uses this method.

    2. The 2nd method floats all of the slides, then duplicates the first and last slide. The first slide is added after the last and the last slide duplicate is added before the first. Then when you are on the last slide and press next, the cloned slide moves into view. When the animation is complete, reposition the view to the first slide. This method is used my jQuery AnythingSlider.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a jQuery content slider that will eventually look like this
I am trying to create a jQuery content slider that will stop when a
Hello Guys! I have been trying to create a cool Image Slider using Jquery!
Recently, I have been trying to accomplish creating a full-width jQuery slider that would
I'm trying to create a JQuery slider and I've hit a roadblock. I'm new
I am trying to create a panorama slider as a jQuery plugin, and I
I'm trying to create a function that uses jQuery to get height of image,
I'm trying to create a jQuery Slider like this . I can't find any
I'm trying to create a jQuery widget which extends from ui.slider . I'd like
I am trying to integrate jquery image slider. But I need to slide the

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.