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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:17:05+00:00 2026-05-28T17:17:05+00:00

How can I create a vertical slider with jQuery? Here’s what I’ve got so

  • 0

How can I create a vertical slider with jQuery? Here’s what I’ve got so far:

JSFIDDLE: http://jsfiddle.net/vkA2w/

HTML:

<div id="vslider">
    <div id="vslidernav">
        <ul>
            <a id="1"><li>Box 1</li></a>
            <a id="2"><li>Box 2</li></a>
            <a id="3"><li>Box 3</li></a>
            <a id="4"><li>Box 4</li></a>
            <a id="5"><li>Box 5</li></a>
        </ul>
    </div>
    <div id="vsliderboxes">
        <div id="box1" class="active"><h1>Clean Interface Design</h1></div>
        <div id="box2" class="inactive"><h1>Efficient Code For Faster Loads</h1></div>
        <div id="box3" class="inactive"><h1>Work Within Any Budget</h1></div>
        <div id="box4" class="inactive"><h1>Less Time Building, More Time Using</h1></div>
        <div id="box5" class="inactive"><h1>Powerful Applications</h1></div>
    </div>
</div>

jQuery:

$(function(){

    boxheight = $('.box').height()
    nextbox = $('.active').next()

    function clickslide(){
    };

    function autoslide(){
        $(nextbox).animate(function(){scrollTop: boxheight}).addClass('active').prev().removeClass('active')
    };

    $('#vslidernav ul a').click(clickslide)
    window.setInterval(autoslide, 2000)

});

Why doesn’t that work? The variable ‘next box’ picks the active box, then should select the box immediately after it. Then the autoslide function should slide it down. Then it gives itself the active class and removes it from the previous box.

But it doesn’t work! Why? 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-05-28T17:17:06+00:00Added an answer on May 28, 2026 at 5:17 pm

    Demo: http://jsfiddle.net/vkA2w/4/

    //cache the box elements so we don't have to look them up every iteration
    var $vsliderboxes = $('#vsliderboxes').children();
    function autoslide(){
    
        //get the current active box
        var $active = $vsliderboxes.filter('.active');
    
        //check to see if the current active box is the last in the slider
        if ($active.index() === ($vsliderboxes.length - 1)) {
            //we need to loop back to the beginning
            var $next = $vsliderboxes.eq(0);
        } else {
            var $next = $active.next();
        }
    
        //slide the active slide out of view, when that is done, remove the active class from the element
        $active.slideUp(300, function () {
            $active.removeClass('active');
        });
    
        //slide the next slide into view, when that is done, add the active class to the element
        $next.slideDown(300, function () {
            $next.addClass('active');
        });
    }
    

    UPDATE

    As a bonus, here is a method to get the navigation links working:

    function clickslide(){
        clearInterval(intervalTimer);
        clearTimeout(timeoutTimer);
        timeoutTimer = setTimeout(function () {
            intervalTimer = window.setInterval(autoslide, 2000);
        }, 2500);
        var $active = $('.active'),
            $next   = $vsliderboxes.eq($(this).index());
        if ($active[0].id !== $next[0].id) {
            $active.slideUp(300, function () {
                $active.removeClass('active');
            });
            $next.slideDown(300, function () {
                $next.addClass('active');
            });
        }
    }
    
    var intervalTimer = window.setInterval(autoslide, 2000),
        timeoutTimer;
    

    UPDATE

    Ok last update, here is a demo: http://jsfiddle.net/vkA2w/8/

    JS–

    $(function(){
    
        //cache all necessary elements, notice the use of the `var` statement so we don't create global variables for no reason
        var $vsliderboxes = $('#vsliderboxes'),
            $vslidernav   = $('#vslidernav'),
            boxHeight     = $vsliderboxes.height(),
            current_index = 0;
    
        function clickslide(){
    
            //stop the slideshow for a bit so we don't get two animations too close together
            clearInterval(intervalTimer);
            clearTimeout(timeoutTimer);
            timeoutTimer = setTimeout(function () {
                intervalTimer = window.setInterval(autoslide, 2000);
            }, 2500);
    
            //first get the index of the clicked link
            var index = $(this).index();
    
            //set the current_index variable to keep track of the current index
            current_index = index;
    
            //then animate
            $vsliderboxes.children().stop().animate({
                top : (boxHeight * index * -1)
            }, 500);
        }
    
        function autoslide(){
    
            //increment the current index
            current_index++;
    
            //loop back to the beginning if necessary
            if (current_index >= $vsliderboxes.children().children().length) {
                current_index = 0;
            }
    
            //trigger a click on the proper index of nav elements to start the animation, this saves having to write the animation code twice
            $vslidernav.find('a').eq(current_index).trigger('click');
        }
    
        $vslidernav.find('a').click(clickslide);
    
        //save the interval timer to a variable so it can be canceled
        var intervalTimer = window.setInterval(autoslide, 2000),
            timeoutTimer  = null;
    
    });
    

    HTML —

    <div id="vsliderboxes">
        <div id="vsliderboxs-inner">
            <div id="box1" class="active"><h1>Clean Interface Design</h1></div>
            <div id="box2" class="inactive"><h1>Efficient Code For Faster Loads</h1></div>
            <div id="box3" class="inactive"><h1>Work Within Any Budget</h1></div>
            <div id="box4" class="inactive"><h1>Less Time Building, More Time Using</h1></div>
            <div id="box5" class="inactive"><h1>Powerful Applications</h1></div>
        </div>
    </div>
    

    CSS —

    #vsliderboxs-inner {
        position : relative;
        width    : 900px;
        height   : 250px;
    }
    #vsliderboxes {
        position : relative;
        overflow : hidden;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can create new Silverlight App with .NET RIA Services enabled. But when I
I am trying to create a vertical scroller using jquery and I am having
I am using the jQuery UI slider and trying to show a div when
Iv created a basic vertical sliding menu which can be seen here on the
How can I, create a vertical line between the open brace and close brace
can anybody please tell me how to create vertical gallery in android? Is it
I'm looking for a way I can create a div which will be fixed
I would like to create a status item with a vertical slider in it,
I have to create a vertical menu using clutter in C. Can anyone help
I know that using the Insert menu, you can create a matrix with vertical

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.