(Note: For a detailed step-by-step tutorial on this topic, click here .)
Hey, did you know you can expand text using a “Read More” button with just a few lines of code?
Here’s how:
-
Add a multi-state box (MSB) to your page.
Now you’re in State1 of the MSB. You can rename the “State1” state ID to “collapsedState” in the Properties Panel. -
Add content to the state, including the short version of the text you’d like to display.
-
Add a transparent button from the Add panel.
-
Change the button text to “Read More” and append it to the end of your short text.
-
Duplicate the first state by clicking the MSB and then clicking Manage States > Duplicate State .
Now you’re in State2. You can rename the “State2” state ID to “expandedState”. -
Add the expanded content to your state.
-
Change the “Read More” button text to “Read Less” and move it to the end of the expanded text.
-
Add the following code to your onReady() function:
$w("#readMoreButton").onClick(() => {
$w("#myStatebox").changeState("expandedState");
});
$w("#readLessButton").onClick(() => {
$w("#myStatebox").changeState("collapsedState");
});
Tip! If you don’t want a border around your multi-state box, choose a non-blank MSB from the Add panel, change the MSB background color to match your page background color, disable the shadow setting, and set the border opacity to 0.
BTW - We’re locking these posts so that any requests for help with Velo can be maintained in the Community Discussion section. Please post your questions or feedback there.