Problem:
I’m working on a website where there is a “dial” that displays a number of tabs representing different divisions of an umbrella company:

At the moment I have everything prepared in HTML/CSS (positioning of each of the tabs). The inner circles are on a higher z-index as the tabs will need to animate outward when rolled over (I can achieve this part). The images for the tabs actually look like this:

Unfortunately it didn’t occur to me until now that because of the mechanics of rollover and rollout in JavaScript, the boundaries for each item are square, meaning they overlap all over the place. For example, the centre circle’s rollover area is actually this:

Which detracts some massive clickable/rolloverable areas on the inner circle of tabs. This effect then stacks with each of the tabs, rendering a standard approach non-viable.
Approach:
This is fine, what I plan to do now is measure the distance and angle of the mouse from the centre of the dial and use these values to determine the relevant tab, and work from there. I’ll basically do the following:
- Collect
angle(using atan2) anddistance(using pythag). - Apply my
.click()to the entire dial, and work with these values from there. - Use
setInterval()to constantly check which item is rolled over and work with its animation from there.
Question:
I’m not exactly sure how to implement what I am doing (with JQuery). I know how to do all the Math stuff once I have the coordinates that I need, I’m just not confident in getting the actual coordinates (ensuring the same results cross-browser).
How can I best gather the coordinates of:
- The centre of my dial.
- The cursor (assuming that the cursor is within the same axis as the centre of my dial i.e. rolling over the centre of the dial will mean both sets of coordiantes are the same).
Note:
Taking the above, anything that achieves the same result (being able to have proper rollover detection for overlapping elements) is equally as helpful.
You can define an image map over the stack of layers. The map will define clicking/hovering regions, and the browser will take care of hit detection. With Adobe ImageReady, I have mapped a portion of your reference image so that “Reprise” and “Initiative” are hotspots:
ImageReady produced the following HTML:
(As you can see, mapping arbitrary regions can be exausting, and I dare to say virtually impossible without the use of a tool.)
You’d apply the map to a transparent image on top of everything. The final assembly can be imagined as the following stack:
The regions were highlighted just for reference. The real composition should be 100% transparent.
Good luck!