Text aufklappen

anndra

Grünschnabel
Hallo,
ich habe aus einer Bleiwüste erstmal Abschnitte mit aufklappbarem Text gemacht. Wenn man auf die Überschrift klickt, erscheint der Text, klickt man auf die nächste Überschrift, klappt sich der nächste Text auf und der eben gelesene zu. Das funktioniert gut.

Jetzt würde ich aber gerne unter der Überchrift jeweils die ersten Zeilen anzeigen und dann mit einem Link wie "weiterlesen" den gesamten Absatz anzeigen. So wie ich es gelöst habe, bleibt dann natürlich der Link "weiterlesen" stehen, was blöd aussieht. Wie kann ich das verschönern? Geht das überhaupt mit html? Danke für Hilfe.

Hier der derzeitige Code:
HTML:
<p><strong>Ueberschrift<strong></p>
Erste Textzeilen blablabla <a href ="/tester/#" onclick="aufklappen('menue1')">weiterlesen</a><br />
<div id="menue1" style="display: none;" >noch viel mehr Text blablabla blablabla.</div>
 
Danke allen für die Tipps. Ich habe jetzt dieses hier:

http://www.cssplay.co.uk/menu/more

angepasst. Mein Code sieht so aus:

HTML:
<style type="text/css">

.holder {width:600px; margin:5px; padding:1em; border:1px solid #ddd;}
.holder h2 {text-align:left;}
a.hid {color:#000; text-decoration:none;}
a.hid em {display:none; color: #000000; text-decoration:none;}
a.hid:hover {text-decoration:none;}
a.hid:active, a.hid:focus {background:#fff; text-decoration:none;}
a.hid:active span, a.hid:focus span {display:none; text-decoration:none;}
a.hid:active em, a.hid:focus em {display:block; width:100%; font-style:normal; cursor:default; text-decoration:none;}
.clear {clear:both;}


</style>


<div class="holder">
<h2>Überschrift<h2>
<p>kurze Einleitung </p>
<p><a class="hid" href="more" onclick="this.hideFocus=true" onblur="this.hideFocus=false"><span>weiterlesen</span>
<em>weiterer Text blablabla</em></a></p></div>


Ergebnis: Läuft super im Firefox.
- In Opera zeigt es den em-Teil mit Underline, wie kriege ich das weg?
- Im IE klappt es den em-Text immer gleich zurück. Ich finde nicht den Javascript-Code, der das offenbar verhindert, hilft mir jemand?
- In Chrome sowie im Safari klappt weder der Original-Code noch mein angepasster. Was kann ich tun? Wenn es nicht anders geht, muss ich es eben so einrichten, dass in diesen Browsern der komplette Text steht, also nix auf- oder zugeklappt wird. Aber wie mache ich das?

Danke allen!
Anndra
 
Für die Browserkompatibilität bzgl. des Mausklickverhaltens kommt hier nur die empfohlene JS-Variante in Frage, die genau aus diesem Grund vom Autor entwickelt wurde.
 
Ich schätze, ich muss Code aus dem Quelltext kopieren. Ich finde ihn nicht, ehrlich! Es geht nicht um Faulheit, ich arbeite seit Tagen an dem Ding und werde es auch verstehen... aber hier stehe ich schlichtweg auf dem Schlauch. Bitte den Code nennen oder wenigsten die Zeile im Quelltext...
 
Die relevanten Bausteine sind in der Tat im Quellcode der Demo-Seiten zusammenzusuchen, wenn, wie im ersten Beispiel, kein direkter Download zur Verfügung bereitsteht.

  • Show me some more...again
  • Download: Download more_again.zip
  • jQuery - show me some more
  • "Komprimierter" Quellcode:
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> stu nicholls dot com | various - jQuery - more and less </title>
<meta name="Author" content="Stu Nicholls" />

<style type="text/css">
.show {cursor:pointer; color:#c00; display:block; text-align:right;}
.hidden img {float:left; padding:10px 10px 10px 0;}
p.jfy {text-align:justify;}
</style>

<script src="http://code.jquery.com/jquery-latest.js"></script>

<script type="text/javascript">

/* ================================================================ 
This copyright notice must be untouched at all times.
Copyright (c) 2009 Stu Nicholls - stunicholls.com - all rights reserved.
=================================================================== */
$(document).ready(function(){

$(".hidden").hide();
$(".show").html("show ....");

$(".show").click(function() {
if (this.className.indexOf('clicked') != -1 ) {
		$(this).prev().slideUp(500);
		$(this).removeClass('clicked')
		$(this).html("show ....");
		}
		else {
		$(this).addClass('clicked')
		$(this).prev().slideDown(500);
		$(this).html("... hide");
		}
});

});
</script>

</head>

<body id="www-stunicholls-com">


<h2>Alice's Adventures in Wonderland</h2>
<p class="bold">by Lewis Carroll</p>
<p class="bold">Down the Rabbit-Hole</p>

<p class="jfy">ALICE was beginning to get very tired of sitting by her sister on the bank and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, "and what is the use of a book," thought Alice, "without pictures or conversations?'</p>
<div class="hidden">
	<img src="more/rabbit.jpg" alt="rabbit" title="" />
	<p class="jfy">So she was considering, in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.</p>
	<p class="jfy">There was nothing so very remarkable in that; nor did Alice think it so very much out of the way to hear the Rabbit say to itself "Oh dear! Oh dear! I shall be too late!" (when she thought it over afterwards it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but, when the Rabbit actually took a watch out of its waistcoat-pocket, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and was just in time to see it pop down a large rabbit-hole under the hedge.</p>
</div>
<i class="show"></i>

<hr />

<h2>Through the Looking Glass</h2>

<p class="bold">by Lewis Carroll</p>

<p class="bold">Looking Glass House</p>

<p class="jfy">One thing was certain, that the white kitten had had nothing to do with it: -- it was the black kitten's fault entirely. For the white kitten had been having its face washed by the old cat for the last quarter of an hour (and bearing it pretty well, considering); so you see that it couldn't have had any hand in the mischief.</p>
<div class="hidden">
	<img src="more/glass.jpg" alt="rabbit" title="" />
	<p class="jfy">The way Dinah washed her children's faces was this: first she held the poor thing down by its ear with one paw, and then with the other paw she rubbed its face all over, the wrong way, beginning at the nose: and just now, as I said, she was hard at work on the white kitten, which was lying quite still and trying to purr -- no doubt feeling that it was all meant for its good.</p>
	<p class="jfy">But the black kitten had been finished with earlier in the afternoon, and so, while Alice was sitting curled up in a corner of the great arm-chair, half talking to herself and half asleep, the kitten had been having a grand game of romps with the ball of worsted Alice had been trying to wind up, and had been rolling it up and down till it had all come undone again; and there it was, spread over the hearth-rug, all knots and tangles, with the kitten running after its own tail in the middle.</p>

</div>
<i class="show"></i>


</body>
</html>
 
Zurück