I like to have a slideshow for my hero section und 2 buttons to switch between the states. I saw this video here and he is using the code below to set a timer to change states.
In the comments someone asked him if its possible to get a next and preview button and he said yes.
“You can use any trigger in order to change states.For click you can use the following:$w(‘ #nextButton ’).onClick(() => { ….changeState function……})”
…I don’t get it.
$w.onReady(function () {
var states = ['state1', 'state2', 'state3'];
var stateNumber = 0;
function slideShow() {
$w('#multiStateBox1').changeState(states[stateNumber]);
if (stateNumber < states.length - 1) {
stateNumber++;
} else {
stateNumber = 0;
}
setTimeout(slideShow, 6000);
}
slideShow();
});
@stschuele Gotcha. Yes. It is weird to right it out with the ellipses like … but the function is here :
$w("#myStatebox").changeState("state2");
That will tell the box to change to the relevant state you want. Note that “#myStatebox” is the id for your Multistate box and “state2” in the code above in the example is the state you want to go to so need to change it appropriately. In my test site, mines looks like this:
export function buttonEvenMore_click(event) {
$w('#multiStateBox1').changeState('state3');
}
That should work with the timer too if it happens before things time elapses.