Javascript Mouseover

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Javascript Mouseover

    Hallo!
    Folgende einfache Bildvertauschung per Mouseover funktioniert in Mozilla, nicht aber im Internet Explorer 6 (es findet keine Vertauschung statt). Weiß jemand, wo es da genau hängt? Laut SelfHTML kennt IE ab 5.5 schon den Befehl getElementsByTagName.

    Quellcode

    1. <a href="fotos.html" onmouseover="this.getElementsByTagName('img')[0].src='fotos2.png';" onmouseout="this.getElementsByTagName('img')[0].src='fotos.png';" onclick="this.getElementsByTagName('img')[0].src='fotos2.png';"><img src="fotos.png" width="100" height="30" alt="Fotos" title="Fotos" /></a>


    Vorher hatte ich die Mousover-Attribute bei img und dann einfach this.src='', aber das versteht der IE ja auch nicht.
  • Probier's mal so ...
    Gib deinem Image eine id und spreche diese dann mit document.getElementById('Bild') an. Sollte dann klappen!

    Quellcode

    1. <a href="fotos.html" onmouseover="document.getElementById('Bild').src='fotos2.png';" onmouseout="document.getElementById('Bild').src='fotos.png';" onclick="document.getElementById('Bild').src='fotos2.png';"><img id="Bild" src="fotos.png" width="100" height="30" alt="Fotos" title="Fotos" /></a>

    Grüße KMD
  • das läuft beim IE zwar auch nicht, aber immerhin kommt kein gelbes warndreieck mehr!

    so lautet der code im moment:

    Quellcode

    1. <a href="index.php?show=fotos&amp;lang=de" onmouseover="document.getElementById('fotos').src='fotos2.png';" onmouseout="document.getElementById('fotos').src='fotos.png';" onclick="document.getElementById('fotos').src='fotos2.png';"><img src="fotos.png" width="100" height="30" id="fotos" alt="Fotos" title="Fotos" /></a>
  • Ich glaube mittlerweile, es hängt mit meinem PNGFIX-Script zusammen!
    da kann man dann wohl nichts machen außer GIFs produzieren oder den IE außen vor lassen.

    Quellcode

    1. <!--[if lt IE 7.]>
    2. <script defer type="text/javascript" src="pngfix.js"></script>
    3. <![endif]-->


    Quellcode

    1. /*
    2. Correctly handle PNG transparency in Win IE 5.5 & 6.
    3. http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.
    4. Use in <HEAD> with DEFER keyword wrapped in conditional comments:
    5. <!--[if lt IE 7]>
    6. <script defer type="text/javascript" src="pngfix.js"></script>
    7. <![endif]-->
    8. */
    9. var arVersion = navigator.appVersion.split("MSIE")
    10. var version = parseFloat(arVersion[1])
    11. if ((version >= 5.5) && (document.body.filters))
    12. {
    13. for(var i=0; i<document.images.length; i++)
    14. {
    15. var img = document.images[i]
    16. var imgName = img.src.toUpperCase()
    17. if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
    18. {
    19. var imgID = (img.id) ? "id='" + img.id + "' " : ""
    20. var imgClass = (img.className) ? "class='" + img.className + "' " : ""
    21. var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
    22. var imgStyle = "display:inline-block;" + img.style.cssText
    23. if (img.align == "left") imgStyle = "float:left;" + imgStyle
    24. if (img.align == "right") imgStyle = "float:right;" + imgStyle
    25. if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
    26. var strNewHTML = "<span " + imgID + imgClass + imgTitle
    27. + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
    28. + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
    29. + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
    30. img.outerHTML = strNewHTML
    31. i = i-1
    32. }
    33. }
    34. }
    Alles anzeigen


    Das simpelste Mouseover-Script ist sowieso:

    Quellcode

    1. <a href="index.php?show=fotos&amp;lang=de"><img src="fotos.png" width="100" height="30" onmouseover="this.src='fotos2.png';" onmouseout="this.src='fotos.png';" onclick="this.src='fotos2.png';" alt="Fotos" title="Fotos" /></a>

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von wulfgang ()