JQuery - onMouseOver(save current opacity, set opacity to 1.0) - onMouseOut( set opacity to saved value) - please help

Well th Q Title propably says it al - but here it goes.

On a intranet page, I append DIV's to a page from a XML file using JQuery. If a data-set meets certain criteria, the DIV is faded to 0.4.
Now I want the DIV to fade back to 1.0 when the user Hovers, but when when the user (unhover ?) the DIV should fade back to original value.
This is because not all DIV's are faded to 0.4, some to 0.75 depending on "value" - I found that this makes it alot easier to focus on the elements that need user attention.

Anyone out there willing to make a few JQuery lines for me :-)

Who is Participating?
RoonaanConnect With a Mentor Commented:
A similar problem is described here: http://markmail.org/message/ccjqhkxzlbmmy6tt

the hoverIntent plugin described there seems to apply to your situation as well: http://cherne.net/brian/resources/jquery.hoverIntent.html

Are you able to set a class to differ between the two styles?

Then you could use the below lines, replacing someclass with the class on the elements that need 0.4 opacity onblur.

var onHoverIn = function(){$(this).fadeTo("slow", 1);}
var onHoverOut = function()$(this).fadeTo("slow", $(this).hasClass('someclass') ? 0.4 : 0.75);}

$(elementSelector).hover(onHoverIn, onHoverOut);
trg_dkAuthor Commented:
>Roonaan - thx for your reply.
In my current setup I can't distinguish between which has 0.4 0.75 or 1.0 in opacity.

Can yopu explain the line
$(elementSelector).hover(onHoverIn, onHoverOut); - How do I use that in my current setup, where I Append each DIV using JQuery. SHould it be a part of the html I append or something that I add after ?

Is it possible to "save" the current Opacity using JQuery ??
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

trg_dkAuthor Commented:
Revisiting your code - I could use a specific class for each and then attach this function I guess.

The page reloads the XML every 30 sec. and update values in each DIV, if a certain value (minutes since last update) is above a certain value, I change the class - I would then append the hover function right there - correct ??

Should I remove the function or will it replace an existing hover function ?? (being revisited every 30 secs this happens quite often)
Yes that would be correct. The problem with storing the original value is that when you hover in/out and back in when the animation has not finished, then you get a wrong "original" value, messing up your system.

trg_dkAuthor Commented:
>Roonan - it works - almost like a charm :-)

I have an extra Q if it is allright ? :

As it works now, the computer gets quite busy fading up and down, when the mouse passes over eg. 70 DIV's.

Is it possible to implement a delay - so the user must hover at least eg. 500 ms before the fadeup occurs ?

Thanks for your help.

trg_dkAuthor Commented:
Just so very perfect - thanks for your help :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.