【问题标题】:Figma Plugin: callback on file updatedFigma 插件:文件更新回调
【发布时间】:2021-02-27 04:22:04
【问题描述】:

我发现回调 'on' 很有趣但限制了https://www.figma.com/plugin-docs/api/properties/figma-on/#docsNav

我有办法在文件更新后触发事件吗?

【问题讨论】:

    标签: javascript plugins figma


    【解决方案1】:

    目前没有办法做到这一点。您可以获得的唯一更新类型是选择更改或当前页面更改。这是一个例子from the docs

    figma.on("selectionchange", () => { console.log("changed") })
    

    插件常用来监视节点变化的方法是轮询:只需创建一个间隔或计时器,并检查其中一个属性是否从先前保存的状态发生变化。

    let interval = setInterval(checkNodes, 500) // check every 300ms
    
    const node = figma.currentPage.selection[0] // first node in selection
    let nodeWidth = node.width // store node properties to watch
    
    function checkNodes() {
      if (nodeWidth !== node.width) {
        // width changed
      }
      nodeWidth = node.width
    }
    

    【讨论】:

      猜你喜欢
      • 2023-02-04
      • 2023-02-04
      • 2021-11-07
      • 2020-03-06
      • 1970-01-01
      • 2020-07-23
      • 2022-08-04
      • 2023-02-04
      • 2023-02-03
      相关资源
      最近更新 更多