Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change opacity?

Status
Not open for further replies.

darkprince

Programmer
Jun 4, 2002
165
AU
hey

i was wondering if i could make it so that when my mouse isn't over the image the opacity is say 75% but when i hold my mouse over the image it goes to 100% opacity?

i dont know if you can do this but anyway

thanks in advance

ciao
 
You will need two images to accomplish this. Set the main image as the 75% opaque one. Then use a mouseover to insert the 100% image. DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
actually there is a way to do it using scripting.

I do it on my personal site ( check on the right side of the page. I actually use an API in JavaScript that I made to help me do it. But if you want here the snippet you'd really need to make it happen on your site :

<script>

// this function is a piece of the API just plug it in the top of your page
function Div(id)
{
var obj = false, type = typeof id;

if(typeof id == &quot;string&quot;)
{
obj = xapi.dom ? document.getElementById(id) : document.all[id] ;
}
else if (type.indexOf(&quot;object&quot;) != -1)
{
obj = id;
}

if (!obj)
{
return false;
}

// special
obj.getOpacity = function()
{
/opacity=(\d{1,3})/i.test(obj.style.filter);
return (_ie) ? RegExp.$1 : parseInt(obj.style.MozOpacity) ;
}

obj.setOpacity = function(o)
{
if (xapi.moz)
{
obj.style.MozOpacity = o + &quot;%&quot;;
}
else if (obj.style.filter)
{
obj.style.filter = 'alpha(opacity=' + o +')'
}
}
}
</script>

<img src=&quot;imgs/home.gif&quot; id=&quot;homeIco&quot; onmouseover=&quot;Div(this.id).setOpacity(100)&quot; onmouseout=&quot;Div(this.id).setOpacity(50)&quot; style=&quot;cursor:pointer;Moz-Opacity-:50%;filter:alpha(opacity=50);&quot; width=&quot;32&quot; height=&quot;25&quot; alt=&quot;Go back home&quot;>

I just ripped this whole thing out of my site maybe I forgot a detail or something. Let me know if it works for you. Gary Haran
 
hey thanks but it didn't work but i prob put it on the page wrong this is what the whole thing looks like



<html>
<head><title>img</title></head>

<script>

// this function is a piece of the API just plug it in the top of your page
function Div(id)
{
var obj = false, type = typeof id;

if(typeof id == &quot;string&quot;)
{
obj = xapi.dom ? document.getElementById(id) : document.all[id] ;
}
else if (type.indexOf(&quot;object&quot;) != -1)
{
obj = id;
}

if (!obj)
{
return false;
}

// special
obj.getOpacity = function()
{
/opacity=(\d{1,3})/i.test(obj.style.filter);
return (_ie) ? RegExp.$1 : parseInt(obj.style.MozOpacity) ;
}

obj.setOpacity = function(o)
{
if (xapi.moz)
{
obj.style.MozOpacity = o + &quot;%&quot;;
}
else if (obj.style.filter)
{
obj.style.filter = 'alpha(opacity=' + o +')'
}
}
}
</script>


<body>


<img src=&quot;left1.JPG&quot; id=&quot;homeIco&quot; onmouseover=&quot;Div(this.id).setOpacity(100)&quot; onmouseout=&quot;Div(this.id).setOpacity(50)&quot; style=&quot;cursor:pointer;Moz-Opacity-:50%;filter:alpha(opacity=50);&quot; alt=&quot;Banner&quot;>


</body>

</html>



thanks in advance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top