Skip to content
Advertisement

I’m going to try to circulate the div once every three days using the order of the css. What should I do?

I am try to set the order of several elements via jQuery.

The base date is the date hard-coded.

The code I have is as follows.

JavaScript

First a-b-c-d-e.
After three days b-c-d-e-a.
Six days later, c-d-e-a-b.
Nine days later, d-e-a-b-c.
Twelve days later, e-a-b-c-d.
I want to be a-b-c-d-e again in 15 days.

Additional temps may be added.

If there’s one more, First a-b-c-d-e-f.
After three days b-c-d-e-f-a.
Six days later, c-d-e-f-a-b.
Nine days later, d-e-f-a-b-c.
Twelve days later, e-f-a-b-c-d.
Fifteen days later, a-b-c-d-e-f.
I want to be a-b-c-d-e-f again in 21 days.

Advertisement

Answer

Can you explain it in more detail?

  • pick your start date
JavaScript
  • calculate how many days it’s been since that date Using this answer

  • how many times to rotate, is ([days since start] / [number of days]) % [how many items]

JavaScript
  • “rotate” them by simply moving the first to the last that number of times
JavaScript

in a loop below, for simplicity, but you could also use .slice and move them all in a single operation if there’s 100s

Example code snippet, change the start date in the code to see the effect

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement