webForumDet fria alternativet

tolka som float, tolkas inte som float.. I don't get it!

1 svar · 374 visningar · startad av oGGo

oGGoMedlem sedan apr. 2003120 inlägg
#1

Hej!
Sitter här och meckar med ett litet fadingscript. Problem har dock uppkommit som jag inte riktigt kan förstå.
När man hovrar ett objekt så anropas funktionen fade(this.id);

fade() går vidare in i fadeIt() och startar en timer för endera funktionen mouseOver() eller mouseOut(), detta är ju tämligen logiskt.

Problemet uppkommer dock i min funktion mouseOut().
I mouseOver() fadas det som det skall medan det i mouseOut() inte gör det.

Problemet ligger i att i mouseOut() så returneras inte värdet från: document.getElementById(id).style.opacity som en float utan som en sträng vilket bara det är skumt då det fungerar utmärkt i mouseOver() funktionen.

Okej, document.getElementById(id).style.opacity = parseFloat(document.getElementById(id).style.opacity) borde då göra susen, men icke.. what have I done wrong här egentligen? =/

function fade(id)
{
	//onmouseover
	if (document.getElementById(id).style.opacity == '')
	{
		document.getElementById(id).style.opacity = 1.0;
		fadeIt('mouseover', id);
	}
	
	else if (document.getElementById(id).style.opacity >= 0.90)
		fadeIt('mouseover', id);
	
	//onmouseout
	else
		fadeIt('mouseout', id);
}

function fadeIt(ud, id)
{
	
	if (ud == 'mouseover')
	{
		var x = 0;
		for (i=0; i<=3; i++)
		{
			setTimeout('mouseOver("'+ id +'");', x);			
			x += 10;
		}
	}

	else if (ud == 'mouseout')
	{
		var x = 0;
		for (i=0; i<=3; i++)
		{
			setTimeout('mouseOut("'+ id +'");', x);			
			x += 10;
		}
	}
}

function mouseOut(id)
{
	if (document.getElementById(id).style.opacity != 1)
	{
		document.getElementById(id).style.opacity += 0.05;
	}
}

function mouseOver(id)
{
	if (document.getElementById(id).style.opacity != 0.5)
	{
		document.getElementById(id).style.opacity -= 0.05;
	}
}
oGGoMedlem sedan apr. 2003120 inlägg
#2

Löste det själv till slut.. satte några parseFloat() på diverse ställen vilket till slut fick det att fungera. Det skumma i kråksången var dock att det fungerade att subtrahera men inte addera.. ytterst märkligt.

parseFloat

oGGo skrev:

function fade(id)
{
	//onmouseover
	if (document.getElementById(id).style.opacity == '')
	{
		document.getElementById(id).style.opacity = 1.0;
		fadeIt('mouseover', id);
	}
	
	else if (document.getElementById(id).style.opacity >= 0.90)
		fadeIt('mouseover', id);
	
	//onmouseout
	else
		fadeIt('mouseout', id);
}

function fadeIt(ud, id)
{
	
	if (ud == 'mouseover')
	{
		var x = 0;
		for (i=0; i<=3; i++)
		{
			setTimeout('mouseOver("'+ id +'");', x);			
			x += 10;
		}
	}

	else if (ud == 'mouseout')
	{
		var x = 0;
		for (i=0; i<=3; i++)
		{
			setTimeout('mouseOut("'+ id +'");', x);			
			x += 10;
		}
	}
}

function mouseOut(id)
{
	if (parseFloat(document.getElementById(id).style.opacity) != 1)
	{
		document.getElementById(id).style.opacity = parseFloat(document.getElementById(id).style.opacity) + 0.05;
	}
}

function mouseOver(id)
{
	if ( parseFloat(document.getElementById(id).style.opacity) != 0.7)
	{
		document.getElementById(id).style.opacity -= 0.05;
	}
}
132 ms totalt · 3 externa anrop · v20260731065814-full.30151723
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
123 ms — hämta tråd, inlägg och bilagor (db)