Skip to content

Instantly share code, notes, and snippets.

@gavinmcfarland
Last active April 14, 2021 21:21
Show Gist options
  • Save gavinmcfarland/255578790e09da53a6d92b245a24c346 to your computer and use it in GitHub Desktop.
Save gavinmcfarland/255578790e09da53a6d92b245a24c346 to your computer and use it in GitHub Desktop.
Figma helper to toggle layer ordering using 180 hack to match z-index of web
function reverseChildren(children) {
const length = children.length
for (let i = 0; i < length; i++) {
var oppIndex = length - i
children[i].parent.insertChild(oppIndex, children[i])
}
}
function toggleLayerZindexOrdering(node) {
if (node.rotation === 0) node.rotation = 180
else if (node.rotation === 180) node.rotation = 0
const length = node.children.length
for (let i = 0; i < length; i++) {
var child = node.children[i]
if (child.rotation === 0) child.rotation = 180
else if (child.rotation === 180) child.rotation = 0
}
if (node.rotation === 180) {
node.x = node.x + node.width
node.y = node.y + node.height
}
else if (node.rotation === 0) {
node.x = node.x - node.width
node.y = node.y - node.height
}
reverseChildren(node.children)
}
toggleLayerZindexOrdering(figma.currentPage.selection[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment