I have created a series of buttons with Raphael that uses a special hover function I borrowed here (see first solution), it basically tells the hover to keep 'hovering' where ever I am inside the circle, regardless of whether my cursor is either on text or the circle. I have used it as shown in this jsfiddle - the hover function can be found in the most top part of the code and is activated right at the bottom of the code. However, whenever I surround the Raphael canvas with any other div that contains the following:
- css margins and padding
- content in div
The special hover function stops working, as shown here. What happens is that my circle buttons revert back to the pre-hover state whenever my cursor goes onto the text part in the middle of the circle. I've realized if I put the Raphael canvas above all the other other divs in the html code, it will work or if I remove all content and styling, it'll work. I can't really do either option. I figured the fault might have something to do with this:
Raphael.el.hoverInBounds = function (inFunc, outFunc) {
var inBounds = false;
// Mouseover function. Only execute if `inBounds` is false.
this.mouseover(function () {
if (!inBounds) {
inBounds = true;
inFunc.call(this);
}
});
// Mouseout function
this.mouseout(function (e) {
var x = e.offsetX || e.clientX,
y = e.offsetY || e.clientY;
// Return `false` if we're still inside the element's bounds
if (this.isPointInside(x, y)) return false;
inBounds = false;
outFunc.call(this);
});
return this;
}
The 'clientX, clientY' part to be exact - after doing some research it seems to me that maybe the function is doing calculations involving the whole page and having content and margin/paddings cause a miscalculation or no calculation at all. I could be wrong. I'm only a beginner at Javascript/Raphael. My questions are: what is causing my hover function to not work properly, and is there any solution/workaround? Thankyou.