Connect failed: Connection timed out

[GastForen Programmierung/Entwicklung JavaScript Toggle Boxen

  • Suche
  • Hilfe
  • Lesezeichen
  • Benutzerliste
Themen
Beiträge
Moderatoren
Letzter Beitrag

Toggle Boxen

KatSe
Beiträge gesamt: 48

24. Jan 2019, 20:45
Beitrag # 1 von 2
Bewertung:
(4522 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
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";
}
}
X

Toggle Boxen

crisies
  
Beiträge gesamt: 138

4. Apr 2019, 20:15
Beitrag # 2 von 2
Beitrag ID: #569643
Bewertung:
(3958 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hi Katrin,

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:

Code
export function button1_click(event) { 
// 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";
}
}


lg
chris.w


als Antwort auf: [#568694]