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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:07:17+00:00 2026-06-01T01:07:17+00:00

I have an image slideshow with navigation, with which I want to add an

  • 0

I have an image slideshow with navigation, with which I want to add an animated element to highlight the active slide, using an arrow graphic which moves to the active slide as the slideshow rotates. I’m using the jQuery Cycle plugin, which adds the ‘activeSlide’ class to the relevant slide number and I’m trying to get the finished result to be something like the slider on http://offerpop.com/, where the arrow moves the active slide automatically, as well as on click.

I’ve been trying to follow what seems to be the same objective from this thread: If $(element) hasClass then .animate() not working? but so far I haven’t got it to function as I’d like to, based on the suggestions of this thread.

So I would be grateful if anyone can help me out and point me in the right direction to which method would be the way to go, as I don’t really know where to start. Thanks

Here’s the navigation part of the code:

<div id="nav">
    <div id="navitem" class="activeSlide"><a>1</a></div>
    <div id="navitem"><a>2</a></div>
    <div id="navitem"><a>3</a></div>
    <div id="navitem"><a>4</a></div>
    <div id="navitem"><a>5</a></div>
</div>

<div id="nav"></div>    
<div id="arrow"></div>​

<script type="text/javascript">
$(document).ready(function() {  
if($('#navitem').hasClass("activeSlide")){
       $("#arrow").animate({marginLeft:"100px"}, 500);
   };
});
</script>
  • 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-01T01:07:19+00:00Added an answer on June 1, 2026 at 1:07 am

    I’ve gone ahead and made a working version for you, complete with comments explaining how everything works. I also corrected some errors in your HTML (multiple elements can’t have the same ID.) Here is the JSfiddle: http://jsfiddle.net/e6r2e/1/.

    HTML:

    <div id="nav">
        <div id="1" class="navitem activeSlide"><a>1</a></div>
        <div id="2" class="navitem"><a>2</a></div>
        <div id="3" class="navitem"><a>3</a></div>
        <div id="4" class="navitem"><a>4</a></div>
        <div id="5" class="navitem"><a>5</a></div>
    </div>
    <div id="arrow"></div>​
    

    CSS:

    .navitem{
        display:block;
        float:left;
        padding:10px 30px;
        cursor:pointer;
    }   
    .activeSlide{
        background:#ccc;
    }
    .activeSlide a{
        color:red;
    }
    #arrow{
        width:10px;
        height:10px;
        background:black;
        position:absolute;
        margin-top:40px;
        left:30px;
    }    ​
    

    JavaScript:

    $(document).ready(function() {
        var slideX = [30, 98, 166, 234, 302], //Define the x-position of the arrow for each slide
            currentSlide = 0; //Current slide variable. Change this to change starting slide.
    
        //Function to change slides. Accepts one parameter, the slide's jQuery object:
        function changeSlide(slide) {
            $('.activeSlide').removeClass('activeSlide'); //Remove previous slide's activeSlide class
            $(slide).addClass('activeSlide'); //Add activeSlide class to current slide.
            $('#arrow').clearQueue().animate({ //Animate the arrow to the correct location. clearQueue is used so that animations aren't stacked:
                'left': slideX[currentSlide] + 'px' //Animate the 'left' selector (Better than margin-left).
            }, 300); //Animation duration in milliseconds.
        }
    
        //Rotate through slides:
        rotate = setInterval(function() {
            //Check if we're on the last slide; if so, return to 0:
            if (currentSlide + 1 >= slideX.length) {
                currentSlide = 0;
            } else {
                currentSlide++;
            }
            //Call the changeSlide function with the slide's jQuery object as the parameter.
            changeSlide($('#' + (currentSlide + 1)));
    
        }, 5000); //Duration to stay on each slide in milliseconds.
        //Animate to clicked slide:
        $('.navitem').click(function() {
            currentSlide = $(this).attr('id') - 1; //Change currentSlide variable to the slide clicked. We use the slide's ID to determine which slide it is, and then subtract one since we deal with numbers starting at 0, not 1.
            changeSlide($(this)); //Call changeSlide function with the new slide's jQuery object as the parameter.
            //Clear and restart our rotate interval so that the timer is reset. Otherwise if we clicked a slide with 1 second left on the timer, it would rotate again in 1 second instead of 5:
            clearInterval(rotate);
            rotate = setInterval(function() {
                if (currentSlide + 1 >= slideX.length) {
                    currentSlide = 0;
                } else {
                    currentSlide++;
                }
                changeSlide($('#' + (currentSlide + 1)));
            }, 5000);
    
        });
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create image slideshow in android. I have many images in android
I have an image slideshow, which has a small DIV on top of it
I have made a simple image slideshow using jQuery. I need the next button
I have created a 4 image endless slideshow, which works more or less well
I have an audio track with an image slideshow - e.g. there's image 1
I have a subclass of UIScrollView that I'm using for images slideshow, with infinite
I have a function that advances a slideshow image when a user clicks a
I'm using the jQuery Cycle plugin to create an image slideshow. It works great,
I have a web page with an image slideshow. JQuery calls a Flex app
I must have looked at hundreds by now ... I want a slide show

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.