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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:58:02+00:00 2026-06-09T10:58:02+00:00

I was able to write a JavaScript carousel and thought it might be more

  • 0

I was able to write a JavaScript carousel and thought it might be more compact to use CSS transitions with nth-child selectors like this:

img {
    transition: all 1s linear; /* or corresponding vendor prefixes */
    position:absolute;
}

img:nth-child(1) {
    top: 0%;
    left: 0%;
}

img:nth-child(2) {
    top: 0%;
    left: 50%;
}

/*and so on...*/

The items would then be rotated by appending the first child or prepending the last child of the container:

parent.appendChild(parent.children[0]);

This approach works well for all but the appended element. It is removed entirely and then reattached, so it ends up in the right spot but does not use the transition effect. Is there a way to use CSS transitions even when relocating an element in the DOM?

jsFiddle Demo – Click the document to advance the images.

  • 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-09T10:58:04+00:00Added an answer on June 9, 2026 at 10:58 am

    I ended up using a data-* attribute and selector. It is a little more verbose than nth-child, but has the advantage of working. It is also cleaner than parsing through class lists.

    Each element has a data-order attribute, which can be assigned with HTML or JavaScript:

    <img src="http://placekitten.com/203/203" data-order=0 />
    

    Replace nth-child with the attribute selector:

    img[data-order="1"] {
        top: 0%;
        left: 50%;
    }
    

    When rotating, increment the order in the dataset. This seems to update the attribute, even though we are modifying the property:

    var forEach = [].forEach,
        nodes = document.body.children,
        length = nodes.length;
    
    //On rotate:
    forEach.call(nodes, function(node) {
        node.dataset.order++;
        node.dataset.order %= length;
    });
    

    Here is the final result.

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

Sidebar

Related Questions

I am trying to write my own Javascript Framework something like jQuery. I use
I'd like to be able to write a time string that looks like this:
I want to be able to write javascript that executes on a page that
What I am trying to do is to be able to write javascript blended
I want to write some JavaScript that is able to detect/read the name of
I'd like to write a small JavaScript (framework) that can chain functions with all
I'm trying to write a javascript with jquery which should be able to pick
Users will be able to write some documents. Those documents will consists of chapters
I am able to write a data frame to an excel file, using the
I was able to write some code with the help of the community here,

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.