Mouseover Fadeeffekt
Paddel
- javascript
Hallo alle,
ich hänge zur Zeit an dem Problem, dass ich einen Script für das Faden von Bildern bei Mouseover gefunden habe (50% --> 100% Opacity), jedoch das ganze nicht umdrehen kann.
Zur Zeit fadet das Script beim Mouseout das Bild nicht wieder auf 50% runter sondern es springt direkt auf 50%.
hier der ursprüngliche Script:
#################################################################
<script language="JavaScript">
function increase(img) {
theobject = img;
highlighting = setInterval("highlight(theobject)",75);
}
function decrease(img) {
clearInterval(highlighting);
if (img.style.MozOpacity)
img.style.MozOpacity = 0.5;
else if (img.filters)
img.filters.alpha.opacity = 50;
}
function highlight(img) {
if (img.style.MozOpacity < 1)
img.style.MozOpacity = parseFloat(img.style.MozOpacity) + 0.1;
else if (img.filters && img.filters.alpha.opacity < 100)
img.filters.alpha.opacity += 5;
else if (window.highlighting)
clearInterval(highlighting);
}
</script>
#################################################################
Hier mein umgearbeiteter: (funktioniert nicht)
<script language="JavaScript">
function increase(img) {
theobject = img;
highlighting = setInterval("highlight(theobject)",75);
}
function decrease(img) {
theobject = img;
decreasing = setInterval("dehighlight(theobject)",75);
}
function dehighlight(img){
clearInterval(highlighting);
if (img.style.MozOpacity > 0.5)
img.style.MozOpacity = parseFloat(img.style.MozOpacity) - 0.1;
else if (img.filters && img.filters.alpha.opacity > 50)
img.filters.alpha.opacity -= 5;
else if (window.decreasing)
clearInterval(dehighlighting);
}
function highlight(img) {
clearInterval(dehighlighting);
if (img.style.MozOpacity < 1)
img.style.MozOpacity = parseFloat(img.style.MozOpacity) + 0.1;
else if (img.filters && img.filters.alpha.opacity < 100)
img.filters.alpha.opacity += 5;
else if (window.highlighting)
clearInterval(highlighting);
}
</script>
#################################################################
Ich hoffe ihr könnt mir irgendwie bei dem Problem weiterhelfen .. ist zwar nicht weltbewegendes wäre aber doch eine kleine aber feine Verbesserung :)
mfG Paddel
Hallo Paddel,
function increase(img) {
highlighting = setInterval("highlight(theobject)",75);
function decrease(img) {
decreasing = setInterval("dehighlight(theobject)",75);
Die Rückgabe von setInterval()
müsste sich im clearInterval()
wieder finden. Tut es das?
Grüße,
Jochen
Ah danke Jochen hab den Fehler gesehen und geändert.
Leider funktioniert der Script immernoch fehlerhaft ..
<script language="JavaScript">
function increase(img) {
theobject = img;
highlighting = setInterval("highlight(theobject)",75);
}
function decrease(img) {
theobject = img;
dehighlighting = setInterval("dehighlight(theobject)",75);
}
function dehighlight(img){
clearInterval(highlighting);
if (img.style.MozOpacity > 0.5)
img.style.MozOpacity = parseFloat(img.style.MozOpacity) - 0.1;
else if (img.filters && img.filters.alpha.opacity > 50)
img.filters.alpha.opacity -= 5;
else if (window.dehighlighting)
clearInterval(dehighlighting);
}
function highlight(img) {
clearInterval(dehighlighting);
if (img.style.MozOpacity < 1)
img.style.MozOpacity = parseFloat(img.style.MozOpacity) + 0.1;
else if (img.filters && img.filters.alpha.opacity < 100)
img.filters.alpha.opacity += 5;
else if (window.highlighting)
clearInterval(highlighting);
}
</script>
als Überprüfung mal die Seite auf der der Script zum Einsat kommt:
http://www.final-power.de/clan/splash.html
(Die beiden Bilder rechts und links auf dem weißen Balken)
mfG Paddel
Hallo Paddel,
<script language="JavaScript">
function increase(img) {
theobject = img;
highlighting = setInterval("highlight(theobject)",75);
}
highlighting (und dehighlighting) sind lokale Variablen der Methoden increase() (und decrease())
[lokale und globale Variablen](http://de.selfhtml.org/javascript/sprache/variablen.htm#definieren)
Im Scope einer anderen Methode sind sie unbekannt. In diesem Zusammenhang eine Frage: Mit welchem Browser testet du, und kennst du die javascript-Konsole des Firefox? Eine überaus nützliche Hilfe bei der Fehlersuche.
Grüße,
Jochen
--
Heute schon gescribbelt?
[Scribbleboard](http://www.electric-lemon.de/scribbleboard.php)
danke jochen
mein bruder hat zusätzlich bei der problemfindung geholfen und nun funktioniert alles
mfg Paddel