We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

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

trg_dk
trg_dk asked
on
Medium Priority
4,380 Views
Last Modified: 2012-05-06
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 :-)

Thanks,
Mark
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2006

Commented:
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);

Author

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 ??

Author

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)
CERTIFIED EXPERT
Top Expert 2006

Commented:
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.

-r-

Author

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.

Mark
CERTIFIED EXPERT
Top Expert 2006
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Just so very perfect - thanks for your help :-)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.