Hallo zusammen, ich weiß nicht, ob das hier der richtige Ort ist. Aber ich verzweifel grad. Ich baue bei WIX eine Webseite auf. Ja ich weiß, sehr dilettantisch. Nun muss ich eine Box hinbekommen, die sich aufklappt und Text zeigt. Mit der Hilfe auf der Seite komme ich nicht weiter. Ich kann zwar Text aufklappen. Aber sobald ich den Button anklicke verschwindet der Text inkl. Button. Vielleicht hat jemand einen Rat?
Viele Grüße Katrin
Hier mal der Code:
let fullText; // variable to hold the full text let shortText; // variable to hold the short version of the text
$w.onReady(function () { // how many characters to include in the shortened version const shortTextLength = 14; // read the full text and store it in the fullText variable fullText = $w("#text29").text; // grab the number of characters defined in shortTextLength and store them in the shortText variable shortText = fullText.substr(0, shortTextLength) + "..."; // set the contents of the text element to be the short text $w("#text29").text = shortText;
});
export function button1_click(event) { // display the full text $w("#text29").text = fullText; // collapse the button $w("#button1").collapse();
// check the contents of the text element if ($w("#text29").text === shortText) { // if currently displaying short text, display the full text $w("#text29").text = fullText; $w("#button1").label = "Show less"; } else { // if currently displaying full text, display the short text $w("#text29").text = shortText; $w("#button1").label = "Show more"; } }
sofern man nicht auch noch den entsprechenden HTML Code dafür sieht, könnte man versuchen zu raten, doch das ist vermutlich nicht ganz korrekt ;)
Aber generell machst Du beim Click auf den Button folgendes: // display the full text $w("#text29").text = fullText; // collapse the button $w("#button1").collapse(); => also zeigst immer den Vollen-Text und machst Button.collapse(). Danach kommt ein If welcher immer wieder den Short-Text zeigen würde. Also versuche das evlt. mal so:
lg chris.w ************************************* Chris Würsch http://www.chriswuersch.com *************************************