Javascript

Javascript-Tooltips einsetzen

Interaktiv Informationen auf einer Web-Seite anzeigen

Gerade auf Gebäudegrundrissen und ähnlichen Bildern ist es manchmal etwas schwer alle Informationen unterzubringen. Besser und schicker ist es da mit dem Benutzer zu interagieren und ihm einen Tooltip mit allen Informationen anzuzeigen, sobald er mit dem Mauszeigen einen bestimmten Bereich berührt.

Zu diesem Zweck nehmen wir das Bild des Grundrisses und legen eine sog. Image-Map darüber. In Microsoft Frontpage z.B. müssen Sie dazu lediglich das in die Seite eingefügte Bild markieren und über die "Bilder"-Symbolleiste sog. Hotspots zeichnen. Am besten eignen sich hierfür polygone Hotspots.

Die Definition der Test-Image-Map in diesem Artikel:

<map name="mapTest">
<area shape="polygon" coords="32, 17, 95, 17, 97, 68, 33, 70">
<area shape="polygon" coords="33, 73, 76, 70, 77, 103, 34, 104">
<area shape="polygon" coords="77, 71, 95, 70, 96, 123, 77, 124">
<area shape="polygon" coords="44, 106, 76, 105, 76, 125, 44, 125">
<area shape="polygon" coords="43, 124, 95, 124, 96, 175, 42, 174">
<area shape="polygon" coords="11, 176, 96, 176, 95, 283, 13, 284">
<area shape="polygon" coords="96, 17, 129, 16, 130, 41, 96, 42">
<area shape="polygon" coords="129, 16, 162, 16, 161, 43, 129, 42">
<area shape="polygon" coords="95, 44, 160, 43, 160, 108, 96, 109">
<area shape="polygon" coords="95, 110, 160, 109, 160, 156, 97, 157">
<area shape="polygon" coords="97, 158, 159, 158, 160, 206, 97, 207">
<area shape="polygon" coords="97, 209, 160, 207, 162, 284, 99, 286">
</map>

Man nennt diese Image-Maps auch "verweis-sensitive Grafiken", da man jedem definierten Bereich eine Ziel-URL zuweisen kann. In unserem Fall benötigen wir jedoch keine Sprungmarke, sondern begnügen uns mit dem Zeichen # als Ziel-String, was dazu führt, dass bei einem Klick lediglich an den Anfang der Seite zurückgesprungen wird. Zudem erhält jede AREA einen eindeutigen ID-Wert:

<area ... href="#" id="1" ... >
<area ... href="#" id="2" ... >
...

Die Verknüpfung der Image-Map an das Bild geschieht durch den IMG-Parameter USEMAP:

<img border="0" src="images/test.gif" usemap="#mapTest">

Nun müssen wir als nächstes definieren was bei einer Mausbewegung über einen der Bereiche angezeigt werden soll. Hierzu definieren wir für jede Bereichsinformation ein DIV mit zwei untergeordneten DIV's (Kopfzeile und Inhalt) und geben ihm eine eindeutige ID, die mit der in der Image-Map korrespondiert:

<div class="tooltip" style="width: 200px;" id="d1">
  <div class="head">Schlafzimmer</div>
  <div class="content">13,47 qm</div>
</div>
...

Am sinnvollsten werden die DIV's im unteren Teil des HTML-Codes angelegt, denn sie sind zum einen zunächst nicht sichtbar und zum anderen später auch nicht dort wo sie definiert sind, denn die Position ist später abhängig vom Maus-Cursor. Um das Ganze etwas aufzuhübschen legen wir im HEAD für die einzelnen DIV's CSS-Formatierungen an:

<style><!--
.tooltip {
  font-size: 10pt;
  position: absolute;
  display: none;
  background-color: #EDECF4;
  border-width: 1px;
  border-style: solid;
  border-color: #E2860E; }

.tooltip .head {
  font-weight: bold;
  background-color: #E2860E;
  color: #EDECF4;
  padding: 2px; }

.tooltip .content {
  color: #666666;
  font-weight: bold;
  padding: 4px; }
--></style>

Mit dieser Basis können wir nun daran gehen die Interaktivität einzubauen. Hierzu dienen drei JavaScript-Funktionen, die dazu dienen einen Bereich einzublenden, ihn bei Bewegung der Maus mit dem Cursor mitzuführen und ihn beim Verlassen des Bereichs wieder auszublenden:

<script><!--
  tooltip = null;
  document.onmousemove = updateTooltip;

  function updateTooltip(e) {
    try {
      x = (document.all) ? window.event.x + document.documentElement.scrollLeft: e.pageX;
      y = (document.all) ? window.event.y + document.documentElement.scrollTop: e.pageY;
      if (tooltip != null) {
        tooltip.style.left = (x + 20) + "px";
        tooltip.style.top = (y + 20) + "px";
      }
    } catch (error) { error=null; }
  }

  function showTooltip(id) {
    try {
      tooltip = document.getElementById(id);
      tooltip.style.display = "block"
    } catch (error) { error=null; }
  }

  function hideTooltip() {
    try {
      tooltip.style.display = "none";
    } catch (error) { error=null; }
  }
//--></script>

Die Funktionen werden abschließend in die Ereignisse OnMouseOver und OnMouseOut der einzelnen Image-Map-Bereiche eingetragen:

<area ... onmouseover="showTooltip('d1')" onmouseout="hideTooltip()"
... >
<area ... onmouseover="showTooltip('d2')" onmouseout="hideTooltip()" ...
>
...
Schlafzimmer
13,47 qm
Bad
5,87 qm
Flur
3,85 qm
WC
2,77 qm
Eingang
10,40 qm
Wohnzimmer
35,00 qm
WC
2,85 qm
Balkon
3,40 qm
Schlafzimmer
15,99 qm
Schlafzimmer
11,70 qm
Küche
13,47 qm
Balkon
12,42 qm
kick it on dotnet-kicks.de AddThis 0 wikio-Stimme(n) Trackback-Url...

Schlagworte

511 Kommentare bislang...

  • In Christianity, the wedding was announced to the world of God who want to link the two become one, both sides vowed never to forsake each other's ceremony.TungstenRingsMall <b> bracelets for women</b>
    wholesaler and retailer of tungsten rings, tungsten wedding bands, ceramic ring, tungsten carbide ring, ceramic rings, tungsten ring and tungsten jewelry for men and women. All tungsten rings are never fade, never wear and never deformation. tungsten rings mall have 2000 styles giving you numerous choice <b> bracelets wholesale china</b>
    available and we can made the unique style and different ring size according to your demand.More rings read: Tungsten carbide rings.
    511
    silver bracelet : Samstag, 4. Februar 2012 07:09
  • HYBY118223D1 Friends of my Men's Women's Canada Goose Parka youth, always so good and true to me, I come to mingle my life with yours, and to grow strong with you in good and holy purposes. We of Canada Goose Jackets the upper air, do not live alone; we need your life, as well as you do ours. This communion is as ancient as time, and will endure throughout Canada Goose Banff Parka eternity. Volumes could not tell of the broken households united through this light. Search for its hidden Canada Goose Chateau Parka treasures; they Canada Goose Citadel Parka are worthy of untiring study. Its glory will not fall into your life; it must Canada Goose Snow Mantra be worked out by your own efforts Canada Goose Como Parka and found within your own experience. Thus it will become a part of your immortal self, and help you on Canada Goose Expedition Parka your heavenly way. The skeptic cannot sit and call us who have thrown off the mortal, by words Canada Goose Ontario Parka alone, for only in answer to deep and heartfelt desire do we come and hold communion with our Canada Goose Langford Parka earthly friends. They who seek shall find..
    510
    Canada Goose Como Parka : Donnerstag, 2. Februar 2012 01:58
  • HYBY118223D1 Friends of my <a href="http://www.salecanadagoosejackets.org/"><strong>Men's Women's Canada Goose Parka</strong></a> youth, always so good and true to me, I come to mingle my life with yours, and to grow strong with you in good and holy purposes. We of <a href="http://www.salecanadagoosejackets.org/"><strong>Canada Goose Jackets</strong></a> the upper air, do not live alone; we need your life, as well as you do ours. This communion is as ancient as time, and will endure throughout <a href="http://www.salecanadagoosejackets.org/mens-canada-goose-parka-canada-goose-banff-parka-c-1_18.html">Canada Goose Banff Parka</a> eternity. Volumes could not tell of the broken households united through this light. Search for its hidden <a href="http://www.salecanadagoosejackets.org/mens-canada-goose-parka-canada-goose-chateau-parka-c-1_19.html">Canada Goose Chateau Parka</a> treasures; they <a href="http://www.salecanadagoosejackets.org/mens-canada-goose-parka-canada-goose-citadel-parka-c-1_22.html">Canada Goose Citadel Parka</a> are worthy of untiring study. Its glory will not fall into your life; it must <a href="http://www.salecanadagoosejackets.org/mens-canada-goose-parka-canada-goose-snow-mantra-c-1_24.html">Canada Goose Snow Mantra</a> be worked out by your own efforts <a href="http://www.salecanadagoosejackets.org/mens-canada-goose-parka-canada-goose-como-parka-c-1_21.html">Canada Goose Como Parka</a> and found within your own experience. Thus it will become a part of your immortal self, and help you on <a href="http://www.salecanadagoosejackets.org/mens-canada-goose-parka-canada-goose-expedition-parka-c-1_17.html">Canada Goose Expedition Parka</a> your heavenly way. The skeptic cannot sit and call us who have thrown off the mortal, by words <a href="http://www.salecanadagoosejackets.org/mens-canada-goose-parka-canada-goose-ontario-parka-c-1_6.html">Canada Goose Ontario Parka</a> alone, for only in answer to deep and heartfelt desire do we come and hold communion with our <a href="http://www.salecanadagoosejackets.org/mens-canada-goose-parka-canada-goose-langford-parka-c-1_2.html">Canada Goose Langford Parka</a> earthly friends. They who seek shall find.
    509
    Men's Women's Canada Goose Parka youth, always so good and true to me, I come to mingle my life with yours, and to grow strong with you in good and holy purpo">Canada Goose Jackets : Donnerstag, 2. Februar 2012 01:52
  • 508
    cialis : Mittwoch, 1. Februar 2012 19:24
  • The outcome Coach Outlet of the race, his advisers argued,he had the same percentage of Coach Factory Outlet Tea Party supporters,he also seemed to gain strength Chanel Bags among Tea Party supporters.
    507
    Coach Outlet : Mittwoch, 1. Februar 2012 02:38

Dein Kommentar hierzu...


Kommentar-Feed für diesen Beitrag
Gravatare werden unterstützt .:. eMail-Adressen werden nicht veröffentlicht
 

RSS-Feed

Die URL des Standard-Newsfeed von zerbit.de lautet:

http://www.zerbit.de/rssfeed.aspx

Login


 

 

Statistik



kürzlich kommentiert

Artikel 16

  • Datum: 24.03.2005
    Kategorie: Javascript
    Zugriffe: 9.044
    Kommentare: 511
    Trackbacks: 0

Letzte Beiträge

Kategorien

Buttons & More

Blog-Roll

Banner Piraten-Partei