I ended up using the data-* attribute and a selector. This is a bit 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 HTML or JavaScript:
<img src="http://placekitten.com/203/203" data-order=0 />
Replace nth-child with an attribute selector:
img[data-order="1"] { top: 0%; left: 50%; }
When rotating, increase the order in the dataset . This seems to update the attribute, although we are modifying the property:
var forEach = [].forEach, nodes = document.body.children, length = nodes.length;
Here is the final result .
source share