Last active
July 1, 2025 19:41
-
-
Save tankxu/e9be6a4b88b8c0bbf4b66f4fddd5d3d3 to your computer and use it in GitHub Desktop.
Figma 脚本 - 颠倒排列选中图层位置
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 代码由 Figma Script Generator | PopLab AI App 生成 | |
| // https://poplab.ai/apps/tankXWAJ2nEm6h4bZWZFI | |
| // 获取选中的图层 | |
| const nodes = figma.currentPage.selection; | |
| if (nodes.length < 2) { | |
| figma.notify("请至少选择两个图层"); | |
| } else { | |
| // 保存原始位置 | |
| const positions = nodes.map(node => ({ x: node.x, y: node.y })); | |
| // 交换位置 | |
| const n = nodes.length; | |
| for (let i = 0; i < Math.floor(n / 2); i++) { | |
| // 互换i和n-1-i的坐标 | |
| const tempX = nodes[i].x; | |
| const tempY = nodes[i].y; | |
| nodes[i].x = nodes[n - 1 - i].x; | |
| nodes[i].y = nodes[n - 1 - i].y; | |
| nodes[n - 1 - i].x = tempX; | |
| nodes[n - 1 - i].y = tempY; | |
| } | |
| figma.notify("图层位置已首尾互换"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment