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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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 ??
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)
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

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.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
trg_dkAuthor Commented:
Just so very perfect - thanks for your help :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.