Skip to main content
Solved

How can i use `figma.viewport.scrollAndZoomIntoView()` with "BaseNode"?

  • July 7, 2023
  • 8 replies
  • 653 views

Lovefield1
const allNode = figma.root.findAll();
const target = figma.getNodeById(key);
let pageNode = target[0].parent;

if (pageNode.type == "SECTION") {
    pageNode = pageNode.parent;
}

figma.currentPage = pageNode;
figma.viewport.scrollAndZoomIntoView(target);

This is my code.
I have object key and figma.getNodeById(key) has return BaseNode.
So i want to change page and move screen to object location.
But scrollAndZoomIntoView() function is can’t use with BaseNode.
How can i do?

Best answer by tank666

figma.viewport.scrollAndZoomIntoView([BaseNode])

This topic has been closed for replies.

8 replies

tank666
  • 4873 replies
  • July 7, 2023

As an argument, this method requires an array of objects, not an object.


Lovefield1
  • Author
  • 4 replies
  • July 7, 2023

Yes scrollAndZoomIntoView() function argument is Array. But use this is Error [...target].
Error : “TypeError: value is not iterable”


tank666
  • 4873 replies
  • July 7, 2023

Why are you using the spread syntax?


Lovefield1
  • Author
  • 4 replies
  • July 7, 2023

I want using scrollAndZoomIntoView() function, but this function argument is Array.
figma.getNodeById(key) is return “BaseNode”.
So how can i convert “BaseNode” to Array?


tank666
  • 4873 replies
  • July 7, 2023

Just remove the spread syntax.


Lovefield1
  • Author
  • 4 replies
  • July 7, 2023

Well, “BaseNode” object is can’t use to scrollAndZoomIntoView() function argument.
Is there really no way?


tank666
  • 4873 replies
  • Answer
  • July 7, 2023

figma.viewport.scrollAndZoomIntoView([BaseNode])


Lovefield1
  • Author
  • 4 replies
  • July 7, 2023

Oh, Thanks so mush.