[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-02-16
7
Medium Priority
?
4,366 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
0
Comment
Question by:trg_dk
  • 4
  • 3
7 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 23654284
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);
0
 
LVL 2

Author Comment

by:trg_dk
ID: 23654441
>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 ??
0
 
LVL 2

Author Comment

by:trg_dk
ID: 23654474
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)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 49

Expert Comment

by:Roonaan
ID: 23656689
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-
0
 
LVL 2

Author Comment

by:trg_dk
ID: 23658510
>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
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 2000 total points
ID: 23658637
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

0
 
LVL 2

Author Closing Comment

by:trg_dk
ID: 31547510
Just so very perfect - thanks for your help :-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses
Course of the Month20 days, 3 hours left to enroll

873 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