Solved

Working with Style filters and image rollover

Posted on 2004-09-02
7
258 Views
Last Modified: 2008-02-26
Below I have referenced 2 examples.  The first dsiplays a slightly transparent image and then shows the full color image on mouseover.  I am trying to use the gray filter so that the image is gray and then displays full color on mouseover.  

The javascript references opacity which is why I think the gray filter is not working.  How can I incorporate the gray filter?


<script language="JavaScript1.2">
function makevisible(cur,which){
strength=(which==0)? 1 : 0.2

if (cur.style.MozOpacity)
cur.style.MozOpacity=strength
else if (cur.filters)
cur.filters.alpha.opacity=strength*100
}
</script>

<a href="#"><img width=55 style="filter:alpha(opacity=20);-moz-opacity:0.2" onMouseover="makevisible(this,0)" onMouseout="makevisible(this,1)" src="image.jpg"></a>


******************************

<a href="#"><img width=55 style="FILTER: Gray" onMouseover="makevisible(this,0)" onMouseout="makevisible(this,1)" src="image.jpg"></a>
0
Comment
Question by:Insomniac_PhD
  • 3
  • 2
7 Comments
 
LVL 8

Accepted Solution

by:
_aaron_ earned 250 total points
ID: 11970376
I *think* that this is what ur after:

<script language="JavaScript1.2">
function makevisible(cur,which){
strength=(which==0)? 1 : 0.2

if ( cur.style.filter )
{
if ( cur.style.filter == 'Gray' )
{
   cur.style.filter = ''
}
else
{
   cur.filters.alpha.opacity=strength*100
}
}
}

</script>

<a href="#"><img width=55 style="filter:alpha(opacity=20);-moz-opacity:0.2" onMouseover="makevisible(this,0)" onMouseout="makevisible(this,1)" src="vipAccess.gif"></a>


******************************

<a href="#"><img width=55 style="filter: Gray" onMouseover="makevisible(this,0)" onMouseout="makevisible(this,1)" src="vipAccess.gif"></a>
0
 
LVL 36

Assisted Solution

by:Zyloch
Zyloch earned 250 total points
ID: 11970377
Hi

The best way is to make this style in the head section:

<style type="text/css">

.gray {filter:gray;}

</style>

Then, have the on onmouseover, and onmouseout:

onmouseover="makevisible(this,0);this.className='gray';" onmouseout="makevisible(this,1);this.className='';"

Finally, I recommend you use onmouseover and onmouseout all lowercase. Just a minor points, but it'll validate better for xhtml.

Regards,
Zyloch
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11970379
Oops, sorry aaron

Regards
0
 
LVL 8

Expert Comment

by:_aaron_
ID: 11970385
This will reset the Gray ( in order to remove Gray, it actually removes the filter!) :

<script language="JavaScript1.2">
function makevisible(cur,which){
strength=(which==0)? 1 : 0.2

if ( cur.style.filter )
{
   if ( cur.style.filter == 'Gray' )
   {
      cur.style.filter = ''
   }
   else
   {
      cur.filters.alpha.opacity=strength*100
   }
}

}

function addFilter(cur)
{
   cur.style.filter = 'Gray'
}

</script>

<a href="#"><img width=55 style="filter:alpha(opacity=20);-moz-opacity:0.2" onMouseover="makevisible(this,0)" onMouseout="makevisible(this,1)" src="vipAccess.gif"></a>


******************************

<a href="#"><img width=55 style="filter: Gray" onMouseover="makevisible(this,0)" onMouseout="addFilter(this)" src="vipAccess.gif"></a>
0
 
LVL 8

Expert Comment

by:_aaron_
ID: 11970390
:)
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question