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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:25:33+00:00 2026-05-25T13:25:33+00:00

I am trying to create a carousel, using floated list items. When Next is

  • 0

I am trying to create a carousel, using floated list items.

When Next is pressed the current 4 visible lis are hidden and the next 4 shown for as many times as needed. Though, there may not always be another 4 to show, as in the case below there would only be 2 more to display.

When Prev is pressed the current 4 visible lis are hidden and the previous 4 shown.

It doesn’t need to loop i.e. if Next is pressed enough times it will reach the end, it wont just start back from the beginning again.

http://jsfiddle.net/tw16/5NB6G/

HTML:

<div id="left">Prev</div>
<ul>
    <li>Test 1</li>
    <li>Test 2</li>
    <li>Test 3</li>
    <li>Test 4</li>
    <li>Test 5</li>
    <li>Test 6</li>
</ul>
<div id="right">Next</div>

jQuery/JavaScript:

var listLength = $('ul li').length;
var listCounter = 0;

$("#right").click(function() {
    if (listCounter == listLength - 1) {
        $("ul li").show(400);
        listCounter = 0;
    }
    else {
        $('ul li').eq(listCounter).hide(400);
        listCounter++;
    }
});

Unfortunately, I haven’t been able to adapt the code to the requirements above.

  • 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-25T13:25:34+00:00Added an answer on May 25, 2026 at 1:25 pm

    I experimented a bit and came up with the following:

    var total = $('ul li').length;
    var start = 0;
    var count = 4;
    
    update = function() {
        for (var i = 0; i < total; i++) {
            el = $("ul li").eq(i);
            if (i >= start && i < start + count)
                el.show(400);
            else
                el.hide(400);
        }
    }
    
    $("#right").click(function() {
        start += count;
        if (start >= total)
            start = 0;
        update();
    });
    
    $("#left").click(function() {
        start -= count;
        if (start < 0)
            start = Math.floor(total / count) * count;
        update();
    });
    

    See http://jsfiddle.net/5NB6G/43/ for a live demo.

    EDIT: I just noticed that you don’t need wrapping over the end/beginning. You can use the following then in conjunction with the update function defined above:

    $("#right").click(function() {
        start += count;
        if (start >= total)
            start -= count;
        update();
    });
    
    $("#left").click(function() {
        start -= count;
        start = start < 0 ? 0 : start;
        update();
    });
    
    • 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 carousel similar to http://www.aprica.jp/ , using jQuery and HTML.
I am trying to create a carousel that contains 7 days with items under
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Ok so I am trying create a login script, here I am using PHP5
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different
Trying to create a small monitor application that displays current internet usage as percentage
Trying to create a list to return some JSON data to a view. Following
I'm trying to create a carousel effect that automatically cycles through each pictures every
Trying to create a select list with a first option text set to an
I am trying create alert dailog using glade,but its not working .am i doing

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.