Skip to main content
gamedev.net
🔒 Locked

[web] HTML Opacity JavaScript Question

Started by Flehns Jul 28, 2006 at 6:54 PM 0 replies 800+ views
Original Post
Flehns
Flehns
I was fooling around with the DHTML tutorial on w3schools.com and I found the whole mouse over/changing opacity thing to be very interesting. It reminded me of the sexy play button on the new Windows Media Player cuz of the pulsing look. The tutorial only taught you how to implement the mouseover pulse and simply reset the opacity on mouseout, so I decided to try and implement my own mouseout version, but ran into trouble in two places: 1> If you mouseover then mouseout too fast, the transitions get stuck mid-shift. 2> Using the function for multiple images causes chaos. Basically, I am stuck on how to rearrange/rewrite the code so that it does not mess up so badly. If there are any HTML/&#106avascript gurus out there willing to help me create awesomeness, I would very much appreciate it! Two notes: 1> Sorry for the inconvenience, this DHTML fading stuff only works with IE. 2> I hope it is okay that I linked to a picture on GameDev.

<html>
<head>
<style>
img
{
filter:alpha(opacity=10)
}
</style>
<script type="text/javascript">
function clean(id)
{
interval=setInterval("makeclean('"  + id + "')",6)
}
function foggy(id)
{
interval=setInterval("makefoggy('" + id + "')",6)
}

function makefoggy(id)
{
if(document.getElementById(id).filters.alpha.opacity<=10)
	{
	clearInterval(interval)
	}
else
	{
	document.getElementById(id).filters.alpha.opacity-=10
	}
}
function makeclean(id)
{	
if(document.getElementById(id).filters.alpha.opacity>=100)	
	{
	clearInterval(interval)
	}
else
	{
	document.getElementById(id).filters.alpha.opacity+=10
	}
}
</script>
</head>

<body>
Mouse over the image-link:
<img border="0" id="myImage1" src="http://www.gamedev.net/community/forums/mod/news/icons/news16.png" onmouseover="clean('myImage1')" onmouseout="foggy('myImage1')" /> <img border="0" id="myImage2" src="http://www.gamedev.net/community/forums/mod/news/icons/news16.png" onmouseover="clean('myImage2')" onmouseout="foggy('myImage2')" /> <img border="0" id="myImage3" src="http://www.gamedev.net/community/forums/mod/news/icons/news16.png" onmouseover="clean('myImage3')" onmouseout="foggy('myImage3')" /> <img border="0" id="myImage4" src="http://www.gamedev.net/community/forums/mod/news/icons/news16.png" onmouseover="clean('myImage4')" onmouseout="foggy('myImage4')" /> </body> </html>
..For some odd reason, my plus signs don't show up in the preview window. Well, at any rate, there are plus signs before and after the "id" in the functions.
Mathachew
Mathachew
I haven't looked through your code, but found a similar example here:
http://dynamicdrive.com/dynamicindex4/highlightgrad.htm

The onmouseout event simply resets the image, but you should be able to duplicate the function that fades the image in and reverse it so that the image fades out when you do a onmouseout. And it works in FF and easily on multiple images ;)

Hope it helps.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.