Jump to content
  • Advertisement
Sign in to follow this  
Flehns

Unity [web] HTML Opacity JavaScript Question

This topic is 4494 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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/javascript 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>
<b>Mouse over the image-link:</b><br />

<a href="http://www.yahoo.com">
<img border="0" id="myImage1" src="http://www.gamedev.net/community/forums/mod/news/icons/news16.png" onmouseover="clean('myImage1')" 
onmouseout="foggy('myImage1')" />
</a>

<a href="http://www.yahoo.com">
<img border="0" id="myImage2" src="http://www.gamedev.net/community/forums/mod/news/icons/news16.png" onmouseover="clean('myImage2')" 
onmouseout="foggy('myImage2')" />
</a>

<a href="http://www.yahoo.com">
<img border="0" id="myImage3" src="http://www.gamedev.net/community/forums/mod/news/icons/news16.png" onmouseover="clean('myImage3')" 
onmouseout="foggy('myImage3')" />
</a>

<a href="http://www.yahoo.com">
<img border="0" id="myImage4" src="http://www.gamedev.net/community/forums/mod/news/icons/news16.png" onmouseover="clean('myImage4')" 
onmouseout="foggy('myImage4')" />
</a>

</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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!