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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:56:07+00:00 2026-05-20T04:56:07+00:00

Hey! I am trying to code a simple content/image rotating banner that I can

  • 0

Hey!
I am trying to code a simple content/image rotating banner that I can click left or right arrows to rotate the content..

I have everything coded and it works but in a very beginners way and would really appreciate a better, more robust way to do it.

jQuery("span.left-arrow").click(function() {
    var visible = jQuery("#home_slider .slide:visible").attr("id");
    var slide1 = jQuery("#home_slider #slide1");
    var slide2 = jQuery("#home_slider #slide2");
    var slide3 = jQuery("#home_slider #slide3");
    if (jQuery(visible == "slide1")) {
        jQuery("#home_slider #slide1:visible").fadeOut(function() {
            slide3.fadeIn();
        });
    }
    if (jQuery(visible == "slide2")) {
        jQuery("#home_slider #slide2:visible").fadeOut(function() {
            slide1.fadeIn();
        });
    }
    if (jQuery(visible == "slide3")) {
        jQuery("#home_slider #slide3:visible").fadeOut(function() {
            slide2.fadeIn();
        });
    }
});
// right arrow
jQuery("span.right-arrow").click(function() {
    var visible = jQuery("#home_slider .slide:visible").attr("id");
    var slide1 = jQuery("#home_slider #slide1");
    var slide2 = jQuery("#home_slider #slide2");
    var slide3 = jQuery("#home_slider #slide3");
    if (jQuery(visible == "slide1")) {
        jQuery("#home_slider #slide1:visible").fadeOut(function() {
            slide2.fadeIn();
        });
    }
    if (jQuery(visible == "slide2")) {
        jQuery("#home_slider #slide2:visible").fadeOut(function() {
            slide3.fadeIn();
        });
    }
    if (jQuery(visible == "slide3")) {
        jQuery("#home_slider #slide3:visible").fadeOut(function() {
            slide1.fadeIn();
        });
    }
});

Thanks for the help!

  • 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-20T04:56:08+00:00Added an answer on May 20, 2026 at 4:56 am

    Something like this perhaps:

    EDIT: the click handlers will now allow you to “loop” forward and backwards.

    // a reference to the currently shown slide
    // you will have to initialize this somewhere
    var currentSlide;
    
    jQuery("span.left-arrow").click(function() {
        currentSlide.fadeOut(function(){
            // if it has a previous sibling, use the previous sibling
            // otherwise set it to the last slide
            currentSlide = currentSlide.prev().length ? currentSlide.prev() : currentSlide.siblings().last();
            currentSlide.fadeIn();
        });
    }
    
    jQuery("span.right-arrow").click(function() {
        currentSlide.fadeOut(function(){
            currentSlide = currentSlide.next().length ? currentSlide.next() : currentSlide.siblings().first();
            currentSlide.fadeIn();
        });
    }
    

    Using this method you don’t have to give each slide a unique ID, but the slide elements must be the only children of #home_slider.

    You could initialize with something like:

    jQuery(function(){
        // this loops through all slides when the page loads and
        // assigns the first slide to the variable currentSlide
        // and hides all the others
        jQuery("#home_slider").children().each(function(index){
            index == 0 ? currentSlide = jQuery(this) : jQuery(this).hide();
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey i'm just trying to write some code in DrScheme: ((function (x) (* x
Hey all i am trying to figiure out why my code is not triggering
Hey I'm trying to figure out how to convert a statement that works in
Hey, trying to put a simple png sequence animation into my app. I have
Hey I am trying to make a page that inserts some strings into a
Hey so I'm trying to clean up my code a bit, and I just
Hey there! I'm doing this project and right now I'm trying to: create some
hey Im trying to see if I can connect to an IP address. My
Hey I'm trying to make a clear button for my polish calculator.. code give
Hey everyone i am trying to write this code and I am having problems

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.