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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:56:27+00:00 2026-06-02T07:56:27+00:00

First time posting, please bear with me. I’m trying to create a slideshow that:

  • 0

First time posting, please bear with me.

I’m trying to create a slideshow that:

  • assigns a z-index to each <section>
  • sets all slides with an opacity of 0.7
  • assigns the currently top slide an opacity of 1

Here is the HTML:

<div id="slides">
  <section class="slide">
    <article>
      <h1>6</h1>
    </article>
  </section>
  <section class="slide">
    <article>
      <h1>5</h1>
    </article>
  </section>
  <section class="slide">
    <article>
      <h1>4</h1>
    </article>
  </section>
  <section class="slide">
    <article>
      <h1>3</h1>
    </article>
  </section>
  <section class="slide">
    <article>
      <h1>2</h1>
    </article>
  </section>
  <section class="slide">
    <article>
      <h1>1</h1>
    </article>
  </section>
</div>
<div id="prev">
  <a href="#previous">&larr;</a>
</div>
<div id="next">
  <a href="#next">&rarr;</a>
</div>

Here is the JS so far:

$(document).ready(function() {
  var z = 0;
  var inAnimation = false;

  $('section.slide').each(function() {
    z++;
    $(this).css('z-index', z);
  });

  function swapFirstLast(isFirst) {
    if(inAnimation) return false;
    else inAnimation = true;

    var processZindex, direction, newZindex, inDeCrease;

    if(isFirst) {
      processZindex = z; direction = '-'; newZindex = 1; inDeCrease = 1;
    } else {
      processZindex = 1; direction = ''; newZindex = z; inDeCrease = -1;
    }

    $('section.slide').each(function() {
      if($(this).css('z-index') == processZindex) {
        $(this).animate({ 'top' : direction + $(this).height() + 'px' }, 'slow', function() {
          $(this).css('z-index', newZindex)
          .animate({ 'top' : '0' }, 'slow', function() {
            inAnimation = false;
          });
        });
      } else {
        $(this).animate({ 'top' : '0' }, 'slow', function() {
          $(this).css('z-index', parseInt($(this).css('z-index')) + inDeCrease);
        });
      }

      return false;
    }

    $('#next a').click(function() {
      return swapFirstLast(true);
    });

    $('#prev a').click(function() {
      return swapFirstLast(false);
    });
  });
});

I thought I could insert the following code into the script:

if($(this).css('z-index') == processZindex) {
  $(this).css('opacity', 1);
} else {
  $(this).css('opacity', 0.7);
}

The problem is I can’t seem to get the opacity at 1 to keep up with the z-index value of 6. So I thought about writing $(this).css('z-index') == processZindex as $(this).css('z-index') != 6 but the issue occurs.

Is there a simpler way to code this?

  • 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-02T07:56:28+00:00Added an answer on June 2, 2026 at 7:56 am

    I just used the ordering of elements instead of z-index, using appendTo,preprendTo:

    http://jsfiddle.net/jtbowden/RAT8N/1/

    I couldn’t decide if one function or separate functions was better. Here is two separate functions:

    http://jsfiddle.net/jtbowden/5LJcA/3/

    Is that what you are going for?

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

Sidebar

Related Questions

first time posting here. I'm using a loop to create 3 buttons, but my
That's my first time posting on stackoverflow. I've been finding usefull answers on this
First time Stack Overflow poster. Please bear with me! :) I have a set
This is the first time I am posting a question on stackoverflow, so please
First time posting, I will try to adhere to best practices. I'm trying to
This is my first time posting so bear with me. I have a file
First time posting a question on StackOverflow, so please go easy on me :)
i'm trying to create a cursor for the first time. I have looked at
First time posting, please let me know if this question has already been answered!
this is my first time on posting so if I have done anything please

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.