Anchor to link to an openstate of multi-state box

Hello all,

I have a top-level page with 3 multi-state boxes which are collapsed on view.

I have also added anchors points as sub menus that I would like to link to the relevant open state of the multi-state box.

I am new to Wix and coding but thought I would be able to do so with the ‘viewportEnter’ function?


This is the code for one of the boxes:

$w.onReady(function FeesprivateStatebox() {
 // TODO: write your page related code here...
    $w("#closedButton2").onClick(() => {
        $w("#FeesprivateStatebox").changeState("pvopenState");
    });

    $w("#openButton2").onClick(() => {
        $w("#FeesprivateStatebox").changeState("pvclosedState");
    });
});

Thought that this might be the code for one of the sub-menu anchor point:

export function anchor2_viewportEnter(event) {
 // Add your code for this event here: 
    $w.onReady(function FeesprivateStatebox() {
    $w("#FeesprivateStatebox").changeState("pvopenState");
    });
}

Any advice would be greatly appreciated.

Thanks.

Update: That code actually works, just wasn’t working yesterday for some reason.

One other question… Instead of having the multi-state box open on entering viewport. Is there a way to action the multi-state to open on scroll once past the anchor point?

Here you should find your answer…
https://www.wix.com/corvid/reference/wix-window#top

@russian-dima Thanks, will see if can find something there.