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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:04:58+00:00 2026-06-13T07:04:58+00:00

EDIT: posted on jsfiddle to make it easier to help out: http://jsfiddle.net/GXf45/ I’ve been

  • 0

EDIT: posted on jsfiddle to make it easier to help out: http://jsfiddle.net/GXf45/

I’ve been able to create a slide show (thru the use of tutorials and stack overflow) and now I’m working on adding some functionality; a button for each slide in the show.

the previous and next buttons work perfectly (especially on the first and last slides) but I’m having issues with the intermediate buttons. Later I imagine the jquery adding buttons based on the number of slides.

The code below is just one of the revisions i’m working on. I’m thinking there are LOTS of opportunities to improve what i have. Let me know where my errors are and what you may do to clean this up. Thanks.

The html has some ruby at the beginning which populates a div based on some partials.

html:

<div class='slider'>
    <ul>
    <% Dir["app/views/main/show/*"].each do |file| %>
      <li><%= render :file => Rails.root.join(file).to_s %></li>
    <% end %>
    </ul>

</div>
    <div id='slider-nav'>
    <button data-dir='prev'>Prvious</button>
    <button data-dir='next'>Next</button>
    <button data-dir='1'>1</button>
    <button data-dir='2'>2</button>
    <button data-dir='3'>3</button>
    <button data-dir='4'>4</button>
</div>

js:

$(document).ready(function(){

    var sliderUL = $('div.slider').css('overflow', 'hidden').children('ul'),
    imgs = $('.showScene'),
    imgWidth = $('.showScene').width(),
    imgsLen = imgs.length,
    current = 1,
    totalImgsWidth = imgsLen * imgWidth;


    $('#slider-nav').show().find('button').on('click', function(){
        var direction = $(this).data('dir'),
        loc = imgWidth;

        //update current value
        //(direction == 'next' ) ? ++current : --current;

        if (direction == 'next')
            {
                current += 1; //2
            } 
        else if (direction == 'prev') 
            {
                current -= 1;//0
            }
        else
            {
                current = direction;    
            }

        //if first image
        if ( current == 0 ) {
            current = imgsLen;
            loc = totalImgsWidth - imgWidth;
            direction ='next';
        } else if ( current - 1 == imgsLen){
            current = 1;
            loc = 0;
        }

        transition(sliderUL, loc, direction);

    }); 

    function transition( container, loc, direction ){
        var unit; //-= or +=

        if ( direction && loc !== 0) {
            unit = ( direction == 'next') ? '-=' : '+=';
        }

        container.animate({
            'margin-left': unit ? (unit + loc) : loc
        });

    };


});

css:

*{margin:0px;padding: 0px;}
.showScene{
    width: 800px;
    height: 300px;

}

#slider-nav{
    margin-top: 1em;
    display: none;

}
#slider-nav button{
    padding: 1em;
    margin-right: 1em;
    border-radius: 10px;
    cursor: pointer;
}
.slider{
    width: 800px;
    height: 300px;
    border: 2px solid grey;
    overflow: scroll;

}
.slider ul {
    width: 10000px;
    list-style: none;


}
.slider ul li{
    float:left;
    list-style-type: none;

}
  • 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-13T07:04:59+00:00Added an answer on June 13, 2026 at 7:04 am

    You’re missing the logic that works out the loc and direction parameters for the numbered buttons. Here is the main snippet, note I refactored your code a little to reuse the sliding logic. You just needed to work out how much you need to slide by from your current position, and which direction to slide.

    var num = parseInt(direction);
    if (num !== current) {
        loc = imgWidth*(num -current);
        if (loc < 0) {
            direction = 'prev';
            loc = -loc;
        } else {
            direction = 'next';
        }
        current = num;
        doSlide(direction, loc);
    }
    

    Try this fiddle.

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

Sidebar

Related Questions

You can see it done here http://qunitjs.com/ and broken down here http://jsfiddle.net/xMwT8/8/ *edit (
http://jsfiddle.net/nFFuD/ I'm trying to animate the search field in this example using jquery, making
This is the code I am working with: http://jsfiddle.net/Rr5PL/9/ I am using googles geocoding
EDIT: a few weeks after I posted this question Evan Coury wrote an excellent
I posted another one on this,, but i had to edit it really much...
EDIT : It turned out that this can only be done through an external
EDIT: Simple version of the question: I want to create server variables in the
I've got standard Create() Edit() and Delete() methods on my controllers, and I am
I recently posted this question: jqgrid edit form autocomplete="off" by default, how to change
EDIT Let me get more to the point. I'm trying to create a psuedo

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.