Skip to main content
Solved

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


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])

View original
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

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

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

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

Oh, Thanks so mush.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings