XML technologies / SVG / Interactive graphics / Solutions

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

  1. Opera 4.x and 5.x, Internet Explorer for MacOS, and Netscape 6 or Mozilla do not execute scripts correctly even with SVG Viewer installed. A Mozilla version does offer rudimentary SVG support without a plug-in, but scripting is not fully implemented there either.

  2. Scripts are defined in a <script> tag inside a CDATA section.

  3. The following tags create the navigation bar, but represent only one possible solution. Instead of a symbol, several <rect> tags could also be used.

<defs>
  <symbol>
    <rect id="kasten" x="0" y="0" width="100" height="25" />
  </symbol>
</defs>
<a xlink:href="kontakt.htm">
  <use xlink:href="#kasten" transform="translate(0,0)"/>
  <text x="20" y="17">Kontakt</text>
</a>
<a xlink:href="service.htm">
  <use xlink:href="#kasten" transform="translate(100,0)"/>
  <text x="120" y="17">Service</text>
</a>
<a xlink:href="referenzen.htm">
  <use xlink:href="#kasten" transform="translate(200,0)"/>
  <text x="203" y="17">Referenzen</text>
</a>

  1. To format the rectangles, add stylesheets for the <rect> tag and the <text> tag.

<style type="text/css">
  <![CDATA[
    text {fill:white;font-family:Arial,Helvetica;font-size:14px;font-stretch:expanded;font-weight:bold}
    rect {fill:darkblue;stroke:none}
  ]]>
</style>

  1. Adding the message box requires an additional symbol

<rect class="hinweis" id="hinweiskasten" x="0" y="25" width="300" height="25" />

, inserted using

<use id="hkasten" xlink:href="#hinweiskasten" style="visibility:hidden"/>
<text id="htext" class="hinweis" x="3" y="40" style="visibility:hidden">Hinweis</text>

. The additional stylesheets

rect.hinweis {fill:darkblue;stroke:none;fill-opacity:0.5}
text.hinweis {fill:white;font-family:Arial,Helvetica;font-size:13px;font-stretch:ultra-condensed;font-weight:bold}

provide formatting.

  1. These functions display the text in the message box:

<svg width="300" height="50" onload="init(evt)">
  ...
  <script type="text/ecmascript">
    <![CDATA[
      var svgdok;
      function init(evt)
      {
        var i=0;
        svgdok=evt.getTarget().getOwnerDocument();
      }
      function hovern(evt,strText)
      {
        var sichtbarkeit;
        var objStyle;
        var objStyle2;
        var elem;
        var elem2;
        var ziel;
        ziel=evt.getTarget().getParentNode();
        elem=svgdok.getElementById("hkasten");
        elem2=svgdok.getElementById("htext");
        elem2.getFirstChild().setNodeValue(strText);
        objStyle=elem.getStyle();
        objStyle2=elem2.getStyle();
        sichtbarkeit=objStyle.getPropertyValue("visibility");
        if (sichtbarkeit=="hidden")
        {
          objStyle.setProperty("visibility","visible");
        }
        else
        {
          objStyle.setProperty("visibility","hidden");
        }
        objStyle2.setProperty("visibility",objStyle.getPropertyValue("visibility"));
      }
    ]]>
  </script>

Navigation elements also need event attributes. Grouping them is convenient. Pass the text to display as the function’s second argument: hovern( ).

<g onmouseover="hovern(evt,'Wegbeschreibung, Anschrift, Kontaktformular und Gästebuch.')" onmouseout="hovern(evt,'')">
  <a xlink:href="kontakt.htm">
    <use xlink:href="#kasten" transform="translate(0,0)"/>
    <text x="20" y="17">Kontakt</text>
  </a>
</g>

  1. The easiest way to highlight hovered elements is to change their color, for example by adjusting opacity. Extend the if statement of the function hovern( ) as follows.

if (sichtbarkeit=="hidden")
{
  objStyle.setProperty("visibility","visible");
  ziel.getStyle().setProperty("opacity","0.7");
}
else
{
  objStyle.setProperty("visibility","hidden");
  ziel.getStyle().setProperty("opacity","1");
}

   

 

 

 

back to top